Android custom listview to achieve drop-down refresh

First, the renderings are presented

Today's app, which doesn't have the function of point sliding refresh, is simply too outdated. Because there are many demands, there are naturally many open sources. However, if you want to reference the open source library, it is very troublesome. For example, pulltorefreshview library, if you transplant the open source code into the project, it is very cumbersome. If you use the dependent function, I am very unhappy with obsessive-compulsive disorder. There are also various custom listviews that implement pulltorefreshlistview controls. It is nothing more than adding a control to the header to change the display effect through setpadding. The effect has been too out. Ruyi found that the effect of swiperefreshlayout provided by Google is very good, but I found that the effect of this control on some mobile phones is different. It is estimated that it is related to the V7 package. Therefore, there is this article to customize this favorite effect. First, briefly describe the implementation principle: 1. Rewrite the ontouchevent of listview. In the method, the current state is determined according to the sliding distance and critical value of the finger. It is divided into four states: release_ TO_ REFRESH、PULL_ TO_ Refresh, refresh and done represent release refresh, pull refresh, refresh in progress and default status respectively. 2. Override the OnDraw method of listview to display different graphical representations according to different status values. 3. Depending on the sliding distance, different transparency, arc angle values, coordinates of the overall drawing, etc. are displayed. 4. There are two kinds of graphic changes: 1. Manually trigger, and update the coordinates when sliding a little distance. Such as pull_ TO_ Refresh status, suitable for action in ontouchevent_ Triggered in move. 2. The animation is triggered automatically, such as refresh state and done state, which is suitable for the action in ontouchevent_ In the up method, the animation effect is automatically triggered as soon as the finger is released. 5. The refresh listener must be set before sliding, otherwise it is an ordinary listview.

The code is very simple, with only two files and detailed comments: pulltorefreshlistview class:

Refresh flag class:

When using, the listener must be set to slide effectively:

Two source code files are done, and the demo project is not provided. It's very simple.

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