3 ms·
RecyclerView in fact only knows how to manage a pool of views that get recycled.. hence the name. Recycling is a very common approach to that problem on mobil
by on_and_off 12y ago
RecyclerView in fact only knows how to manage a pool of views that get recycled.. hence the name.
Recycling is a very common approach to that problem on mobile, nothing new here, RecyclerView just specializes in recycling as best as possible.
In order to use it, you need to specify a LayoutManager that will handle how elements are displayed on the screen.
Google provides a linear one, and the community has already been working on Grid and staggered grid.
Compared to ListView, RecyclerView does not make counterproductive assumptions on what it is going to do. ListView has been written in the Blackberry era. Its only goal was to display a static list of item. No animations, no operations on the items, no gestures. It is possible to implement some of these, but for all advanced operations you hit the assumptions that ListView made on how its items are displayed. In the end, you spend more time fighting the widget than building on top of it.
RecyclerView shows a good separation of concerns. You want to implement gestures ? here you go, implement the RecyclerView.OnItemTouchListener interface and you are good to go.
You want custom animations on addition/removal/replacement of an item ? No problem, just implement your own ItemAnimator.
Many parts of the widget have been thought out in order to be customizable and get out of your way and let you build on top of it.
Also, it is part of the support library. Google can update it as many times as necessary and make the changes available on all terminals since it is no longer a part of the platform.
I am sure that RecyclerView has its own quirks and limitations. In fact in the dev preview while ListView only handle Headers and Footers very badly, RecyclerView does not handle them at all. However, it is a very strong foundation on top of which it will be possible to efficiently build an Android app without having to reinvent the wheel.