RecyclerView
is added into v7 support library
since Android API 22 officially. And many people said that it is a enhancement over ListView
and many brief introductions to the usage of it were posted over the internet. But most of these articles are very simple, shallow and hollow. The enhancement is just RecyclerView.ViewHolder
, RecyclerView.ItemAnimator
or RecylerView.SmoothScroller
? Did the recycling and reuse mechanism
of items' views during scrolling differ from the ListView
's? And what exactly is the enhancement
of RecyclerView
over ListView
?
Any answers, tips or links are appreciated. Thanks in advance.
Best Answer
RecyclerView
is not an "enhancement" "overListView
", strictly speaking.ListView
actually does something;RecyclerView
, on its own, does not. A more accurate comparison would be that theRecyclerView
framework is an improvement overAdapterView
, and to some extent theAbsListView
parent class ofListView
andGridView
.RecyclerView
focuses on widget recycling and gross childView
management. It delegates everything else to other classes.AdapterView
does far less of this, making it more difficult to extend functionally.Of note:
Laying out the children, within the scrollable space of the
RecyclerView
, is delegated to managers. Hence, not only do three ship withrecyclerview-v7
(list, grid, staggered grid), but others can be developed for alternative scenarios (e.g., overlapping children, for aStackView
orGallery
sort of experience).Updates from adapters can be much more fine-grained. With
AdapterView
, you pretty much have to redraw the entire view (e.g., aListView
and all its rows) on any change of significance, especially when adding and removing items. The update mechanism in theRecyclerView
adapters indicate the specific positions that change. Not only does this require less processing time, but it helps enable the animated effects thatRecyclerView
offers (again, with pluggable replacements) for adding, moving, and removing items.Other stuff that was "baked into"
ListView
, like drawing dividers, is now pulled out into extension points, such as anItemDecorator
. Now, you can choose how to "decorate" items, with line dividers or boxes or colored bar separators or whatever. Decoration is not limited to "dividers", but can affect anything in the views that, for one reason or another, you consider to be separate from the item views themselves.RecyclerView
, though, is fairly complicated to get going. What you get fromListView
"out of the box" takes a lot more code -- yours or a third-party library's -- to match. For experienced developers, this is a feature, in that the code is replaceable with other code. For newcomers, this is a bug, in that there is a steeper learning curve forRecyclerView
, IMHO.