Android的Recyclerview VS的ListView与Viewholder [英] Android Recyclerview vs ListView with Viewholder

查看:247
本文介绍了Android的Recyclerview VS的ListView与Viewholder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近碰到了android RecycleView 这是发布了Android 5.0,似乎 RecycleView 只是一个封装的传统的ListView 与纳入​​它的ViewHolder模式,促进视图的重用,而不是创建它每一次。

I recently came across the android RecycleView which was released with Android 5.0 and it seems that RecycleView is just an encapsulated traditional ListView with the ViewHolder pattern incorporated into it, which promotes the reuse of the view, rather than the creating it every single time.

什么是使用的其他好处 RecycleView ? 如果双方在性能方面同样的效果,为什么人们会选择使用RecycleView`?

What are the other benefits of using RecycleView ? If both have the same effect in terms of performance, why would one choose to use RecycleView` ?

修改

我发现,人问类似的问题和答案都没有定论,在这里将它们备案。

I found that people have asked similar question and the answers are not conclusive, adding them here for record keeping.

<一个href="http://stackoverflow.com/questions/28392554/should-we-use-recyclerview-to-replace-listview?rq=1">Should我们使用RecyclerView更换的ListView?

<一个href="http://stackoverflow.com/questions/24885223/why-doesnt-recyclerview-have-onitemclicklistener-and-how-recyclerview-is-dif/24933117#24933117">Why不RecyclerView有onItemClickListener()?而如何RecyclerView从列表视图不同?

推荐答案

随着Android的棒棒糖,在 RecyclerView 作出了正式的方式的出现。该RecyclerView得多的强大的,灵活的和主要的改进了的ListView 。我会尽量给你一个详细了解吧。

With the advent of Android Lollipop, the RecyclerView made its way officially. The RecyclerView is much more powerful, flexible and a major enhancement over ListView. I will try to give you a detailed insight into it.

1)ViewHolder模式

在一个ListView,建议使用ViewHolder模式,但它从来就不是一个强迫。万一RecyclerView的,这是强制性的使用<一href="https://developer.android.com/reference/android/support/v7/widget/RecyclerView.ViewHolder.html">RecyclerView.ViewHolder类。这是ListView,并且RecyclerView之间的主要区别之一。

In a ListView, it was recommended to use the ViewHolder pattern but it was never a compulsion. In case of RecyclerView, this is mandatory using the RecyclerView.ViewHolder class. This is one of the major differences between the ListView and the RecyclerView.

这让事情有点在RecyclerView更复杂,但很多问题是我们面临的ListView中有效地解决了。

It makes things a bit more complex in RecyclerView but a lot of problems that we faced in the ListView are solved efficiently.

2)布局管理

这是另一个巨大的提升带来的RecyclerView。在一个ListView,唯一的类型的视图中提供的是垂直的ListView。还有就是即使实施水平的ListView没有正式的办法。

This is another massive enhancement brought to the RecyclerView. In a ListView, the only type of view available is the vertical ListView. There is no official way to even implement a horizontal ListView.

现在使用RecyclerView,我们可以有一个

Now using a RecyclerView, we can have a

我)<一href="https://developer.android.com/reference/android/support/v7/widget/LinearLayoutManager.html">LinearLayoutManager - 支持纵向和横向列表,

i) LinearLayoutManager - which supports both vertical and horizontal lists,

二)<一href="https://developer.android.com/reference/android/support/v7/widget/StaggeredGridLayoutManager.html">StaggeredLayoutManager - 支持Pinterest的像交错名单,

ii) StaggeredLayoutManager - which supports Pinterest like staggered lists,

三)<一href="https://developer.android.com/reference/android/support/v7/widget/GridLayoutManager.html">GridLayoutManager - 支持在画廊的应用程序可见显示网格

iii) GridLayoutManager - which supports displaying grids as seen in Gallery apps.

和最好的事情是我们可以做所有这些动态的,因为我们想要的。

And the best thing is that we can do all these dynamically as we want.

3)项目动画

列表视图是缺乏支持的好动画,但RecyclerView带来了一个全新的境界吧。使用<一个href="https://developer.android.com/reference/android/support/v7/widget/RecyclerView.ItemAnimator.html">RecyclerView.ItemAnimator类,动画的看法变得如此多的方便和直观。

ListViews are lacking in support of good animations, but the RecyclerView brings a whole new dimension to it. Using the RecyclerView.ItemAnimator class, animating the views becomes so much easy and intuitive.

4)项目装饰

在列表视图的情况下,如添加边框和分频器动态装饰物品并非易事。但在情况下的RecyclerView,在<一href="https://developer.android.com/reference/android/support/v7/widget/RecyclerView.ItemDecoration.html">RecyclerView.ItemDecorator类提供了巨大的控制权交给开发商,但做事情有点耗费更多的时间和复杂的。

In case of ListViews, dynamically decorating items like adding borders or dividers was never easy. But in case of RecyclerView, the RecyclerView.ItemDecorator class gives huge control to the developers but makes things a bit more time consuming and complex.

5)OnItemTouchListener

截取项目点击一个ListView很简单,这要归功于它的<一个href="http://developer.android.com/reference/android/widget/AdapterView.OnItemClickListener.html">AdapterView.OnItemClickListener接口。但RecyclerView赋予更多的权力和控制其开发的<一个href="https://developer.android.com/reference/android/support/v7/widget/RecyclerView.OnItemTouchListener.html">RecyclerView.OnItemTouchListener但复杂的事情有点为开发者。

Intercepting item clicks on a ListView was simple, thanks to its AdapterView.OnItemClickListener interface. But the RecyclerView gives much more power and control to its developers by the RecyclerView.OnItemTouchListener but it complicates things a bit for the developer.

在简单的话,该RecyclerView远远比ListView的更加个性化,并给出了大量的控制和权力,它的开发者。

In simple words, the RecyclerView is much more customizable than the ListView and gives a lot of control and power to its developers.

这篇关于Android的Recyclerview VS的ListView与Viewholder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆