国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

Google自己的下拉刷新組件SwipeRefreshLayout

2019-11-09 14:10:53
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

感謝原文作者:http://stormzhang.github.io/android/2014/03/29/android-swiperefreshlayout/

API doc:http://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html首先須把你的support library的版本升級(jí)到19.1或更新

效果:

使用超級(jí)簡(jiǎn)單!

在layout中添加SwipeRefreshLayout

復(fù)制代碼
 1 <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" 2     android:id="@+id/swipe_container" 3     android:layout_width="match_parent" 4     android:layout_height="match_parent" > 5  6     <ScrollView 7         android:layout_width="match_parent" 8         android:layout_height="wrap_content" > 9 10         <TextView11             android:id="@+id/textView1"12             android:layout_width="match_parent"13             android:layout_height="wrap_content"14             android:gravity="center"15             android:paddingTop="10dp"16             android:text="@string/swipe_to_refresh"17             android:textSize="20sp"18             android:textStyle="bold" />19     </ScrollView>20 21 </android.support.v4.widget.SwipeRefreshLayout>復(fù)制代碼

在Activity中使用:

復(fù)制代碼
 1 tv = (TextView)findViewById(R.id.textView1); 2         swipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.swipe_container); 3         //設(shè)置刷新時(shí)動(dòng)畫(huà)的顏色,可以設(shè)置4個(gè) 4         swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_red_light, android.R.color.holo_orange_light, android.R.color.holo_green_light); 5         swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() { 6              7             @Override 8             public void onRefresh() { 9                 tv.setText("正在刷新");10                 // TODO Auto-generated method stub11                 new Handler().postDelayed(new Runnable() {12                     13                     @Override14                     public void run() {15                         // TODO Auto-generated method stub16                         tv.setText("刷新完成");17                         swipeRefreshLayout.setRefreshing(false);18                     }19                 }, 6000);20             }21         });復(fù)制代碼

PS:setColorScheme()已經(jīng)棄用,使用setColorSchemeResources()來(lái)設(shè)置顏色。


發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 英吉沙县| 仲巴县| 通道| 昂仁县| 普兰店市| 惠州市| 来凤县| 平山县| 麦盖提县| 新巴尔虎右旗| 普宁市| 密云县| 襄汾县| 汶上县| 上犹县| 建昌县| 定边县| 西充县| 庐江县| 孟津县| 临海市| 哈密市| 吴川市| 环江| 社旗县| 伊宁市| 庄河市| 宁陵县| 宜黄县| 鹿邑县| 太仓市| 日照市| 富裕县| 五常市| 保德县| 德江县| 交城县| 嘉善县| 平舆县| 平武县| 丹东市|