Android custom drop-down refresh control refreshableview

This is the product of understanding the principle of pull-down refresh function. Pull-down refresh can be said to be a necessary function in domestic apps. Even Google has developed swiperefreshlayout, an MD style pull-down refresh. However, the MD style seems to be very difficult in China, not only because the mainstream of the domestic system is still 4.4, but also because of the problem of user habits. After reading many blogs, I suddenly want to write a pull-down refresh compatible with all controls that can imitate swiperefreshlayout, not only listview, but also ordinary view and Scrollview, After two days of struggle, I finally got it, because my purpose is to refresh the pull-down, so there are few functions. However, if I can refresh the pull-down, other functions can be stacked slowly.

The reason for the new system is that we can't give an appropriate GIF, so we can only take a screenshot:

The first picture shows textview:

The second chapter shows the listview:

The third chapter shows Scrollview:

Basically, this is the successful control I tested. It is the simplest to be compatible with ordinary view. The more complex ones are listview and Scrollview.

Idea: my idea is the same as that of most blogs. Customize a ViewGroup, and then hand over the touch event of the control to be dragged to refreshableview for processing, and dynamically change the margintop value of the headview, as described above. Of course, there are some details to pay attention to, such as the processing of the return value of the ontouch method and the margintop value of the child view.

Source code

First, the layout file of the headview:

Next is the crucial class refreshableview:

use:

In my customized refreshableview, if drop-down listening is not set, there will be no drop-down effect, that is, drop-down is not supported

Source download: Android pull-down refresh control

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

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