Activity_main.xml
<relativelayout xmlns:android="Http://schemas.android.com/apk/res/android"xmlns:tools="Http://schemas.android.com/tools"Android:layout_width="Match_parent"android:layout_height="Match_parent"tools:context="Com.example.xiala.MainActivity"> <android. Support. V4. Widgets. SwiperefreshlayoutXmlns:android="Http://schemas.android.com/apk/res/android"Android:id="@+id/swipe_container"Android:layout_width="Match_parent"android:layout_height="Match_parent"> <scrollview android:layout_width="Match_parent"android:layout_height="Match_parent"> <textview android:layout_width="Match_parent"android:layout_height="Wrap_content"android:layout_margintop="16DP"android:gravity="Center"android:text="@string/hello_world"/> </ScrollView> </android. Support. V4. Widgets. Swiperefreshlayout></RelativeLayout>
Mainactivity.java
ImportAndroid.os.Bundle;ImportAndroid.os.Handler;ImportAndroid.support.v4.widget.SwipeRefreshLayout;ImportAndroid.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;Importandroid.support.v7.app.ActionBarActivity; Public class mainactivity extends actionbaractivity implements Onrefreshlistener{ PrivateSwiperefreshlayout swipelayout;@Override protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (R.layout.activity_main); Swipelayout = (swiperefreshlayout) Findviewbyid (R.id.swipe_container); Swipelayout.setonrefreshlistener ( This); Swipelayout.setcolorscheme (Android. R.color.holo_blue_bright, Android. R.color.holo_green_light, Android. R.color.holo_orange_light, Android. R.color.holo_red_light); } Public void Onrefresh() {NewHandler (). postdelayed (NewRunnable () {@Override Public void Run() {swipelayout.setrefreshing (false); } }, the); }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android drop-down refresh control usage