Analysis of RecycleView source code purposes
RecycleView, as a control that every App will use in a large probability, is of great importance. This control is very simple to use, but it is important to understand how it works. We can take our time solving the metaphysical problems we face.
The main thread of this series of articles
To understand RecyclerView, we must start from the big trunk, and then look at the various functional components inserted in his body, and then understand RecyclerView from the whole control overall architecture. This backbone is RecycleView as a common UI control, how to achieve the function of sliding reusable list. So we have a lot of questions here, like, how do we do sliding? How to measure, draw and arrange each item? What is the cache detail strategy? When do you cache? How do the components work together? How is local refresh implemented? So, let’s look at the trunk first, then look at the slide-cache-various components (Adapter, LayoutManager, ItemAnimator and ItemDecoration), and follow this process. Hope to see this list of articles, you can first list their own problems, with the problem to see.
An overview of the
RecycleView originally has an elder is ListView, what is the difference between these two, RecycleView has what advantages? Why do we want to replace the ListView?
Why RecycleView instead of ListView
As a substitute of ListView, RecycleView has many advantages relative to ListView. The parts are more powerful and easier to expand.
1. Be more powerful with caching
The caching principle of the two is basically the same, the unit of cache is slightly different, ListView cache View, RecycleView cache ViewHolder. But RecycleView has two more layers of caching, and can also be used to customize the cache policy. All RecycleViews can share a cache pool. In addition, when entering the screen from off-screen, it can be directly used if certain conditions are met without re-bind. ListView doesn’t have that.
- Local refreshes are provided
RecycleView provides a local refresh interface, and the underlying layer is also based on the data source, as little as possible to re-render unchanged items during the refresh. Therefore, in the scenario of frequent update of data sources, RecycleView is more efficient.
- Provides waterfall flow, tables and other UI
Writing waterfall streams using ListView is cumbersome, but RecycleView provides a ready-made LayoutManager for use. Tables are also integrated into RecycleView.
- Flexible plug – in components
RecycleView uses the plug-and-pull mode, integrating LayoutManager, ItemDecoration, ItemAnimator many components. Encapsulate each function individually into a cohesive component. More convenient for our use. For example, if we need a new layout method, we can define a LayoutManager to measure the layout of each item again without caring about other functional units.
conclusion
RecycleView is more powerful when local refresh is needed in the scenario of frequent update. And it’s easier to scale. These are all the reasons why we used RecycleView instead of ListView.
Next chapter:
How does RecycleView work as a common UI control? That is, to analyze its backbone: the three processes of surveying and mapping. If you know the trunk, you know the branches and leaves. The next chapter analyzes how RecycleView works as a common UI control.