SwipeRefreshLayout控件使用方法
成都創新互聯服務項目包括遼源網站建設、遼源網站制作、遼源網頁制作以及遼源網絡營銷策劃等。多年來,我們專注于互聯網行業,利用自身積累的技術優勢、行業經驗、深度合作伙伴關系等,向廣大中小型企業、政府機構等提供互聯網行業的解決方案,遼源網站推廣取得了明顯的社會效益與經濟效益。目前,我們服務的客戶以成都為中心已經輻射到遼源省份的部分城市,未來相信會繼續擴大服務區域并繼續獲得客戶的支持與信任!
android.support.v4.widget.SwipeRefreshLayout
界面設計:
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:id="@+id/swipe">
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Random number:"
android:id="@+id/lbl"/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rndNum"
android:layout_toRightOf="@id/lbl"/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/lbl"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="Swipe to Refresh"
style="@android:style/TextAppearance.Medium"/>
java代碼:
final SwipeRefreshLayout swipeView = (SwipeRefreshLayout) findViewById(R.id.swipe); final TextView rndNum = (TextView) findViewById(R.id.rndNum); //設置刷新顏色 swipeView.setColorSchemeResources(android.R.color.holo_blue_light); //設置刷新監聽器 swipeView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { swipeView.setRefreshing(true); Log.d("Swipe", "Refreshing Number"); //Handler更新界面,延時3000毫秒 ( new Handler()).postDelayed(new Runnable() { @Override public void run() { //設置刷新結束 swipeView.setRefreshing(false); double f = Math.random(); rndNum.setText(String.valueOf(f)); } }, 3000); } });
實現效果:
SwipeRefreshLayoutDemo