Android implements pull-up loading and pull-down refresh (listview)

First of all, I will introduce the simple implementation of andorid 5.0 native pull-down refresh.

Effect drawing first;

Compared with the horizontal bar in the previous 19.1.0 version, the effect is much better. It's also easy to use.

A few lines of code can realize the pull-down refresh, and the effect is also good. There is no need to introduce a third-party jar. The only regret is that there is no pull-up loading. I don't know what considerations Google engineers are based on. I hope to see it in the next version. However, it is easy to modify the source code and add a pull-up. Combined with the refresh effect of the previous version, the pull-up effect is good.

2、 Android implements more functions of pull-up loading and pull-down refresh, and adopts the currently popular pulltorefresh, which is a class library for better pull-down refresh. At present, it supports listview, expandablelistview, GridView, WebView, etc. The first step is, of course, to import libriay into our project. The specific import method will not be repeated here. The following is an example using listview. Of course, the rest are similar to this. 1. Layout file activity_ main.xml

2. To implement the pull-down refresh function is very simple, you only need to implement the onrefresh method of onrefreshlistener.

Here's how to pull up and pull down to perform different operations. The principle is to distinguish pull-up or pull-down according to the visible status class of the layout displayed by pull-down and pull-up, and then perform corresponding operations. In the com.handmark.pulltorefresh.library package of pulltorefresh's class library, open pulltorefreshbase.java and add the following code on the last side of this class:

3. The code in activity is as follows:

As shown in the above code, the onrefresh implementation code is used to distinguish between pull-up and pull-down. The key codes are as follows:

At this point, run the project and you can get the demonstration results.

This article has been sorted into "Android pull-down refresh pull-up loading effect", welcome to study and study.

The article is very rich in content. I hope it will help you learn more about Android pull-up loading and pull-down refresh functions.

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
分享
二维码
< <上一篇
下一篇>>