日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

Google官方下拉刷新组件---SwipeRefreshLayout

發(fā)布時(shí)間:2025/3/21 51 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Google官方下拉刷新组件---SwipeRefreshLayout 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
今天在Google+上看到了SwipeRefreshLayout這個(gè)名詞,遂搜索了下,發(fā)現(xiàn)竟然是剛剛google更新sdk新增加的一個(gè)widget,于是趕緊搶先體驗(yàn)學(xué)習(xí)下。

SwipeRefreshLayout

SwipeRefreshLayout字面意思就是下拉刷新的布局,繼承自ViewGroup,在support v4兼容包下,但必須把你的support library的版本升級(jí)到19.1。 提到下拉刷新大家一定對(duì)ActionBarPullToRefresh比較熟悉,而如今google推出了更官方的下拉刷新組件,這無疑是對(duì)開發(fā)者來說比較好的消息。利用這個(gè)組件可以很方便的實(shí)現(xiàn)Google Now的刷新效果,見下圖:

主要方法

  • setOnRefreshListener(OnRefreshListener): 為布局添加一個(gè)Listener
  • setRefreshing(boolean): 顯示或隱藏刷新進(jìn)度條
  • isRefreshing(): 檢查是否處于刷新狀態(tài)
  • setColorScheme(): 設(shè)置進(jìn)度條的顏色主題,最多能設(shè)置四種

xml布局文件

布局文件很簡(jiǎn)單,只需要在最外層加上SwipeRefreshLayout,然后他的child是可滾動(dòng)的view即可,如ScrollView或者ListView。如:
  • <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">
  • ? ? <ScrollView
  • ? ?? ???android:layout_width="match_parent"
  • ? ?? ???android:layout_height="match_parent">
  • ? ?? ???<TextView
  • ? ?? ?? ?? ?android:text="@string/hello_world"
  • ? ?? ?? ?? ?android:layout_width="match_parent"
  • ? ?? ?? ?? ?android:layout_height="wrap_content"
  • ? ?? ?? ?? ?android:layout_marginTop="16dp"
  • ? ?? ?? ?? ?android:gravity="center"/>
  • ? ? </ScrollView>
  • </android.support.v4.widget.SwipeRefreshLayout>
  • 復(fù)制代碼

    Activity代碼

  • 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() {
  • ? ? new Handler().postDelayed(new Runnable() {
  • ? ?? ???[url=home.php?mod=space&uid=389554]@Override[/url] public void run() {
  • ? ?? ?? ?? ?swipeLayout.setRefreshing(false);
  • ? ?? ???}
  • ? ? }, 5000);
  • }
  • 復(fù)制代碼

    ?

    上面的代碼很簡(jiǎn)單,只需要給SwipeRefreshLayout添加一個(gè)listener,值得說明的是setColorScheme方法是設(shè)置刷新進(jìn)度條的顏色,最多只能設(shè)置4種循環(huán)顯示,默認(rèn)第一個(gè)是隨用戶手勢(shì)加載的顏色進(jìn)度條。

    源碼

    寫了的小demo在github上,地址在:SwipeRefreshLayoutDemo

    總結(jié)

    google在不斷完善自己的sdk,推出越來越多的組件,其目的是讓開發(fā)更簡(jiǎn)單,設(shè)計(jì)上更統(tǒng)一,這可能是google未來的方向,不管怎樣,這對(duì)開發(fā)者來說無疑是非常好的消息。

    轉(zhuǎn)載于:https://www.cnblogs.com/xiaochao1234/p/3644998.html

    總結(jié)

    以上是生活随笔為你收集整理的Google官方下拉刷新组件---SwipeRefreshLayout的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。