Android RecyclerView 和 ListView 使用对比分析

论坛 期权论坛     
选择匿名的用户   2021-5-26 13:27   607   0
<p><span style="color:rgb(47,47,47); font-size:16px"></span></p>
<p>今天这篇文章主要是向大家介绍 RecyclerView 和 ListView 的使用对比,文章主要包括以下几点的内容:</p>
<ul style="margin-top:0px; margin-bottom:20px; padding:0px; word-break:break-word; margin-left:22px; color:rgb(47,47,47); font-size:16px"><li style="line-height:30px; margin-bottom:10px">RecyclerView 和 ListView 布局效果的对比</li><li style="line-height:30px; margin-bottom:10px">RecyclerView 和 ListView 一些常用的功能 和 API 的对比</li><li style="line-height:30px; margin-bottom:10px">RecyclerView 和 ListView 在 Android L 引入<span style="font-weight:700">嵌套滚动机制</span>之后的对比</li></ul>
<div>
<span style="white-space:pre"><span style="font-weight:700; color:rgb(47,47,47); font-size:16px">有一点需要强调下,文中所有的效果在真机上都是很流畅的,因为录制 GIF 图很容易掉帧,所以特地放慢了操作,千万不要误会成卡顿了啊!</span></span>
</div>
<div>
<span style="white-space:pre"><span style="font-weight:700; color:rgb(47,47,47); font-size:16px"></span></span>
</div>
<div>
<h2 style="line-height:1.7; color:rgb(47,47,47); margin:0px 0px 15px; font-size:24px"> 布局效果对比</h2>
<span style="color:rgb(47,47,47); font-size:16px">作为一枚控件,要引起开发者使用的欲望自然先是从显示效果看起(看脸的世界),ListView 大家对效果已经很熟悉了,这里直接跳过,而作为 RecyclerView,它能带给效果要比 ListView 强大得多,如下图</span>
</div>
<div>
<span style="color:rgb(47,47,47); font-size:16px"></span>
</div>
<div>
<span style="color:rgb(47,47,47); font-size:16px"><img alt="" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-5dea5ab9f8eaa18a7d39c23d33479cc8"></span>
</div>
<div>
<span style="color:rgb(47,47,47); font-size:16px"></span>
</div>
<div>
<span style="color:rgb(47,47,47); font-size:16px"></span>
</div>
<div>
<span style="color:rgb(47,47,47); font-size:16px"></span>
<p style="margin-top:0px; margin-bottom:25px; word-break:break-word; color:rgb(47,47,47); font-size:16px"> Android 默认提供的 RecyclerView 就能支持 <span style="font-weight:700">线性布局</span>、<span style="font-weight:700">网格布局</span>、<span style="font-weight:700">瀑布流布局</span> 三种(这里我们暂且不提代码细节,后文再说),而且同时还能够控制横向还是纵向滚动。怎样,从效果上足以碾压 ListView 有木有。</p>
<ul style="margin-top:0px; margin-bottom:20px; padding:0px; word-break:break-word; margin-left:22px; color:rgb(47,47,47); font-size:16px"><li style="line-height:30px; margin-bottom:10px"><span style="font-weight:700">横向滚动的ListView开源控件是不是可以不用再找了?对,你没看错!</span></li><li style="line-height:30px; margin-bottom:10px"><span style="font-weight:700">瀑布流效果的开源控件是不是可以不用再找了?对,你没看错!</span></li><li style="line-height:30px; margin-bottom:10px"><span style="font-weight:700">连横向滚动的GridView都不用找了!对,你没看错!</span></li></ul>
<p style="margin-top:0px; margin-bottom:25px; word-break:break-word; color:rgb(47,47,47); font-size:16px"> 到此,展示效果上的差距一目了然。</p>
<p style="margin-top:0px; margin-bottom:25px; word-break:break-word; color:rgb(47,47,47); font-size:16px"> </p>
<h2 style="line-height:1.7; color:rgb(47,47,47); margin:0px 0px 15px; font-size:24px"> API 使用对比</h2>
<span style="color:rgb(47,47,47); font-size:16px">当然,一个控件我们不能完全只看效果,关键还是要看实用性,看看有没有方便我们调用的 API提高我们的开发效率。所以,接下来我们就从各个方面来看看 RecyclerView 和 ListView 在提供的API调用上的一些实践比较。</span>
<p></p>
<p style="margin-top:0px; margin-bottom:25px; word-break:break-word; color:rgb(47,47,47); font-size:16px"> <span style="color:rgb(47,47,47); font-size:16px"></span></p>
<h2 style="line-height:1.7; color:rgb(47,47,47); margin:0px 0px 15px; font-size:24px"> 基础使用</h2>
<p></p>
<p style="margin-top:0px; margin-bottom:25px; word-break:break-word; color:rgb(47,47,47); font-size:16px"> ListView 的基础使用大家再熟悉不过,其使用的关键点主要如下:</p>
<ul style="margin-top:0px; margin-bottom:20px; padding:0px; word-break:break-word; margin-left:22px; color:rgb(47,47,47); font-size:16px"><li style="line-height:30px; margin-bottom:10px">继承重写 BaseAdapter 类</li><li style="line-height:30px; margin-bottom:10px">自定义 ViewHolder 和 convertView 一起完成复用优化工作</li></ul>
<p style="margin-top:0px; margin-bottom:25px; word-break:break-word; color:rgb(47,47,47); font-size:16px"> 由于 ListView 已经老生常谈,所以此处就不去写示例代码了。 RecyclerView 基础使用关键点同样有两点:</p>
<ul style="margin-top:0px; margin-bottom:20px; padding:0px; word-break:break-word; margin-left:22px; color:rgb(47,47,47); font-size:16px"><li style="line-height:30px; margin-bottom:10px">继承重写 Recyc
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP