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.
And what exactly is the enhancement of RecyclerView over ListView?
RecyclerView
is not an "enhancement" "over ListView
", strictly speaking. ListView
actually does something; RecyclerView
, on its own, does not. A more accurate comparison would be that the RecyclerView
framework is an improvement over AdapterView
, and to some extent the AbsListView
parent class of ListView
and GridView
.
RecyclerView
focuses on widget recycling and gross child View
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 with recyclerview-v7
(list, grid, staggered grid), but others can be developed for alternative scenarios (e.g., overlapping children, for a StackView
or Gallery
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., a ListView
and all its rows) on any change of significance, especially when adding and removing items. The update mechanism in the RecyclerView
adapters indicate the specific positions that change. Not only does this require less processing time, but it helps enable the animated effects that RecyclerView
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 an ItemDecorator
. 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 from ListView
"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 for RecyclerView
, IMHO.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With