Detailed explanation of the use of swiperefreshlayout, the official drop-down refresh control for Android
Maybe most people who develop Android have used many open-source components for pull-down refresh, but today swiperefreshlayout, which uses the official V4 support package, thinks the effect is also quite good, so I'd like to share it.
Introduction: the swiperefreshlayout component only accepts one sub component: the component that needs to be refreshed. It uses a listening mechanism to notify the listener owning the component that a refresh event has occurred. In other words, our activity must implement the notification interface. The activity is responsible for handling events and refreshing the corresponding view. Once the listener receives the event, it determines where it should be handled in the refresh process. If you want to show a "refresh animation", it must call setrefreshing (true), otherwise it will call setrefreshing (false) to cancel the animation.
And this thing only supports pull-down refresh. You can customize the view and inherit it to realize your pull-up loading.
How to use swiperefreshlayout:
It's very simple to use.
The following will use an example to show how to use the official drop-down refresh control. At the end, I also simulated the virtual implementation of a small pull-up loading effect, which can be analyzed upward.
Start with the above figure:
Upper point code:
activity_ main.xml
menu_ layout.xml
MainActivity.java
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.