There are also a lot of articles on the internet about the dropdown, but they are too long. Just found the official Drop-down Refresh library, and the effect is good, simple and beautiful, and very convenient to use.
Here is the effect chart:
My friend was empty and refreshed two more.
Use or very convenient, in the layout file to add Swiperefreshlayout, this is the Drop-down refresh layout.
I also joined a ListView in the Swiperefreshlayout because I was mainly using a drop-down refresh to update the contents of the ListView.
Layout file:
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"
android:layout_width= "Match_ Parent "
android:layout_height=" match_parent ">
<android.support.v4.widget.swiperefreshlayout
Android:id= "@+id/id_swipe_ly"
android:layout_width= "match_parent"
android:layout_height= "Match_parent" >
<listview
android:id= "@+id/id_listview"
android:layout_width= "Match_parent"
android: layout_height= "Match_parent" >
</ListView>
</android.support.v4.widget.swiperefreshlayout >
</RelativeLayout>
As soon as the code is written here, a drop-down refresh appears as long as the main interface slides down to the top.
Then we're going to instantiate this Drop-down refresh layout, set what it's going to do when it refreshes, and when the refresh is done, the rotated icon disappears.
Mswipelayout = (swiperefreshlayout) Findviewbyid (r.id.haoyouliebiaoshuaxin);//Instantiate//handler to update the UI
Haoyouhandler = new Handler () {@Override public void Handlemessage (msg) {
Super.handlemessage (msg);
The thing to do Item i1 = new Item ();
I1.name = "hehe";
I1.account = 25566;
Haoyou.add (I1);
Item i2 = new Item ();
I2.name = "haha";
I2.account = 25577;
Haoyou.add (I2);
Haoyouadpter = new Liebiaoadapter (Mainactivity.this, R.layout.liebiao, haoyou);
Haoyoulist.setadapter (Haoyouadpter);
Cancels the updated animation mswipelayout.setrefreshing (false);
}
}; Set Listener Mswipelayout.setonrefreshlistener (new SWIPEREFRESHLAyout.
Onrefreshlistener () {@Override//What code is executing when it is being updated public void Onrefresh () {
New Thread (New Runnable () {@Override public void run () {
Wait one second try {thread.sleep (1000);
catch (Interruptedexception e) {e.printstacktrace ();
//Send a message to handler update UI messages OK = new ();
Haoyouhandler.sendmessage (OK);
}). Start ();
I am in the listener's Onrefresh function, wait a second, and then send a message to handler to update the UI, update and then cancel the update.
The above is the entire content of this article, I hope to help you learn.