Android 5.0 new feature learning summary pull-down refresh (1), android5.0

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.