来自android开发者(创建列表和卡片):
RecyclerView小部件是一个更高级和灵活的版本 列表视图。
好吧,这听起来很酷,但当我看到这张示例图片时,我真的很困惑这两者之间的区别。
上面的图片可以通过ListView使用自定义适配器轻松创建。
那么,在什么情况下应该使用RecyclerView呢?
来自android开发者(创建列表和卡片):
RecyclerView小部件是一个更高级和灵活的版本 列表视图。
好吧,这听起来很酷,但当我看到这张示例图片时,我真的很困惑这两者之间的区别。
上面的图片可以通过ListView使用自定义适配器轻松创建。
那么,在什么情况下应该使用RecyclerView呢?
当前回答
为了使列表视图具有良好的性能,您需要实现holder模式,这很容易搞砸,特别是当您想用几种不同类型的视图填充列表时。
RecyclerView烘焙了这个模式,使它更难以搞砸。它也更灵活,更容易处理不同的布局,不是直线,如网格。
其他回答
为了使列表视图具有良好的性能,您需要实现holder模式,这很容易搞砸,特别是当您想用几种不同类型的视图填充列表时。
RecyclerView烘焙了这个模式,使它更难以搞砸。它也更灵活,更容易处理不同的布局,不是直线,如网格。
我用RecyclerView工作了一点,仍然喜欢ListView。
当然,它们都使用ViewHolders,所以这不是一个优势。 RecyclerView在编码方面更加困难。 RecyclerView不包含页眉和页脚,所以它是一个减号。 ListView不需要创建ViewHolder。如果你想要一个带有分段或子标题的列表,那么创建独立的项(没有ViewHolder)是个好主意,这样更容易,也不需要单独的类。
除了以上差异之外,还有以下几个:
RV separates view creation and binding of data to view. In LV, you need to check if convertView is null or not for creating view, before binding data to it. So, in case of RV, view will be created only when it is needed but in case of LV, one can miss the check for convertview and will create view everytime. Switching between Grid and List is more easy now with LayoutManager. No need to notify and update all items, even if only single item is changed. One had to implement view caching in case of LV. It is provided in RV by default. (There is difference between view caching n recycling.) Very easy item animations in case of RV.
I think the main and biggest difference they have is that ListView looks for the position of the item while creating or putting it, on the other hand RecyclerView looks for the type of the item. if there is another item created with the same type RecyclerView does not create it again. It asks first adapter and then asks to recycledpool, if recycled pool says "yeah I've created a type similar to it", then RecyclerView doesn't try to create same type. ListView doesn't have a this kind of pooling mechanism.
RecyclerView相对于listview的优点:
默认包含ViewHolder。 简单的动画。 支持水平,网格和交错布局
listView相对于recyclerView的优点:
易于添加分隔线。 可以使用内置的arrayAdapter简单的普通列表 支持页眉和页脚。 支持OnItemClickListner。