Android app uses recyclerview to realize pull-up and pull-down refresh

About recyclerview

Recyclerview has been introduced since Android 5.0. The listview often used in the past inherits abslistview, while recyclerview directly inherits ViewGroup and implements the scrollingview and nestedscrollingchild interfaces. Recyclerview is a complete change compared with listview. Recyclerview is more advanced and flexible than listview. For many views, it is a container that can be reused and scrolled effectively. Use it when data changes dynamically. Recyclerview is very convenient to use because it provides: 1. It provides a layoutmanager for item positioning; 2. It provides a default animations for item operation; 3. It can also flexibly define the custom layout manager and animation of this widget

Realize pull-up refresh and pull-down refresh of layout files:

Reference this layout in the activity and initialize it

API to pay attention to in swiperefreshlayout: 1. Setonrefreshlistener (onrefreshlistener listener) sets drop-down listening. When the user drops down, the callback will be executed. 2. Setcolorschemecolors (int... Colors) sets the color change of the progress bar, which can be set to four colors at most. 3. Setprogressviewoffset (Boolean scale, int start, int end) Adjust the distance between the progress bar and the top of the screen. 4. Setrefreshing (Boolean refreshing) sets whether the swipererefreshlayout is currently in the refresh state. Generally, it is set to true when requesting data and false after the data is loaded into the view.

Implementation of recyclerview:

First, both pull-down refresh and pull-up refresh use the progress bar provided by swiperefreshlayout

The second method is to use the progress bar provided by swiperefreshlayout for pull-down refresh, and use a refresh similar to listview to prompt "loading" and other information for pull-up refresh.

We can also add an item similar to footerview to recyclerview. We implement in the adapter:

In this way, we can do some processing for the layout of footerview, such as prompt "loading", "all loaded" and so on. Be more flexible

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>