Android's new Swiperefreshlayout control tutorial

Source: Internet
Author: User

Swiperefreshlayout feeling is that Google absorbed the pulltoRefresh-ListView, Actionbarpulltorefresh after the implementation of the Google-style refresh control, the colorful cross-bar, thick Google flavor.



After migrating to Android studio, you must use Appcompat_v7 21+, and after switching you will find some interesting changes, such as this swiperefreshlayout, evolved into a circle.


So let's see how to use the Swiperefreshlayout!

    • First you need to declare in the layout:

<android.support.v4.widget.swiperefreshlayout xmlns:android= "Http://schemas.android.com/apk/res/android"    android:id= "@+id/swipe_refresh_container"    android:layout_width= "match_parent"    android:layout_ height= "Match_parent"    android:background= "#E4E4E4" ></android.support.v4.widget.swiperefreshlayout >


    • Then you need to initialize the control in your code

  Swiperefreshlayout.setcolorschemeresources (Android. R.color.holo_purple, Android. R.color.holo_blue_bright, Android. R.color.holo_orange_light,                Android. R.color.holo_red_light);        Swiperefreshlayout.setonrefreshlistener (this);
Here the circle sets a number of colors to replace the display, then sets the listener to implement the Onrefresh method of the implements Swiperefreshlayout.onrefreshlistener interface
@Override public    void Onrefresh () {        adapter.sync ();    }


In this case, the Swiperefreshlayout control is displayed when it is pulled down, but the actual requirements are usually loaded with the network request, then it is very simple, when the request start swiperefreshlayout.setrefreshing ( true); Call Swiperefreshlayout.setrefreshing (FALSE) when the request is complete;

Is that all? Yes, it's easy, no longer have to endure Actionbarpulltorefresh's three dependent packages, and compatibility issues in APPCOMPAT_V7 21.


Here's another question,

Android.support.v4.widget.SwipeRefreshLayout
It is not necessary to use in the layout, but it must have only one control inside, and if you can slide, such as Listview,scrollview, if you encounter a sliding exception, you can refer to the following link:
https://yassirh.com/2014/05/how-to-use-swiperefreshlayout-the-right-way/

Sliding problems



Android's new Swiperefreshlayout control tutorial

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.