Android 5.0 new feature learning summary pull-down refresh (1), android5.0
After android 5.0, google added a pull-down refresh control under the support v4 package.
Project address: https://github.com/stormzhang/SwipeRefreshLayoutDemo
Xml: <android. support. v4.widget. SwipeRefreshLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: id = "@ + id/swipe_container"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent">
<ListView
Android: id = "@ + id/listview"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: padding = "16dp"/>
</Android. support. v4.widget. SwipeRefreshLayout> java: Listener implementation:
Implements SwipeRefreshLayout. OnRefreshListener/** Listener SwipeRefreshLayout. the method in OnRefreshListener is triggered after the pull-down refresh */public void onRefresh () {new Handler (). postDelayed (new Runnable () {@ Override public void run () {// stop refreshing mSwipeLayout. setRefreshing (false) ;}}, 5000); // send a message after 5 seconds, stop refreshing} initialize the pull-down refresh control mSwipeLayout = (SwipeRefreshLayout) findViewById (R. id. swipe_container); mSwipeLayout. setOnRefreshListener (this); // set the color of the drop-down circle, blue, green, orange, and red mSwipeLayout. setColorSchemeResources (android. r. color. holo_blue_bright, android. r. color. holo_green_light, android. r. color. holo_orange_light, android. r. color. holo_red_light); mSwipeLayout. setDistanceToTriggerSync (400); // you can specify the distance from the finger to the screen to trigger the pull-down refresh mSwipeLayout. setProgressBackgroundColor (R. color. red); // set the background mSwipeLayout of the drop-down circle. setSize (SwipeRefreshLayout. LARGE); // set the circle size
Official documents: https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.