Android Recyclerview vs ListView with Viewholder [英] Android Recyclerview vs ListView with Viewholder
问题描述
我最近遇到了与 Android 5.0 一起发布的 android RecyclerView
似乎 RecyclerView
只是一个封装的传统 ListView
ViewHolder 模式融入其中,促进了视图的重用,而不是每次都创建它.
I recently came across the android RecyclerView
which was released with Android 5.0 and it seems that RecyclerView
is just an encapsulated traditional ListView
with the ViewHolder pattern incorporated into it, which promotes the reuse of the view, rather than creating it every single time.
使用 RecyclerView
的其他好处是什么?如果两者在性能方面具有相同的效果,为什么更喜欢 RecyclerView`?
What are the other benefits of using RecyclerView
?
If both have the same effect in terms of performance, why would one prefer RecyclerView` ?
编辑
我发现有人问过类似的问题,但答案并不确凿,将它们添加到此处以供记录.
I found that people have asked similar question and the answers are not conclusive, adding them here for record keeping.
我们应该使用 RecyclerView 代替 ListView 吗?
为什么没有 RecyclerView有 onItemClickListener()?以及 RecyclerView 与 Listview 有何不同?
推荐答案
使用RecycleView
的另一个好处是动画,两行代码就可以搞定
The other plus of using RecycleView
is animation, it can be done in two lines of code
RecyclerView.ItemAnimator itemAnimator = new DefaultItemAnimator();
recyclerView.setItemAnimator(itemAnimator);
但是小部件仍然是原始的,例如您不能创建页眉和页脚.
But the widget is still raw, e.g you can't create header and footer.
这篇关于Android Recyclerview vs ListView with Viewholder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!