欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android RecyclerView設(shè)置下拉刷新的實(shí)現(xiàn)方法

 更新時(shí)間:2017年10月09日 10:40:08   投稿:lqh  
這篇文章主要介紹了Android RecyclerView設(shè)置下拉刷新的實(shí)現(xiàn)方法,希望通過(guò)本文通過(guò)SwipeRefreshLayout方式實(shí)現(xiàn)下拉刷新,需要的朋友可以參考下

Android RecyclerView設(shè)置下拉刷新的實(shí)現(xiàn)方法

1 集成 SwipeRefreshLayout

1.1 xml布局文件中使用

<android.support.v4.widget.SwipeRefreshLayout
  android:id="@+id/refresh"
  android:layout_width = "match_parent"
  android:layout_height = "match_parent" >

  <android.support.v7.widget.RecyclerView
    android:id = "@+id/rv_list"
    android:layout_width = "match_parent"
    android:layout_height = "match_parent"
    android:background = "#FF504F4F" />

</android.support.v4.widget.SwipeRefreshLayout >

1.2 設(shè)置下拉刷新樣式

SwipeRefreshLayout swipeRefreshView = (SwipeRefreshLayout) findViewById(R.id.refresh);
// 設(shè)置顏色屬性的時(shí)候一定要注意是引用了資源文件還是直接設(shè)置16進(jìn)制的顏色,因?yàn)槎际莍nt值容易搞混
// 設(shè)置下拉進(jìn)度的背景顏色,默認(rèn)就是白色的
swipeRefreshView.setProgressBackgroundColorSchemeResource(android.R.color.white);
// 設(shè)置下拉進(jìn)度的主題顏色
swipeRefreshView.setColorSchemeResources(R.color.colorAccent, R.color.colorPrimary, R.color.colorPrimaryDark);

1.3 設(shè)置下拉刷新加載監(jiān)聽

final Handler handler = new Handler();
// 下拉時(shí)觸發(fā)SwipeRefreshLayout的下拉動(dòng)畫,動(dòng)畫完畢之后就會(huì)回調(diào)這個(gè)方法
swipeRefreshView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
  @Override
  public void onRefresh() {

    // 開始刷新,設(shè)置當(dāng)前為刷新狀態(tài)
    //swipeRefreshLayout.setRefreshing(true);

    // 這里是主線程
    // 一些比較耗時(shí)的操作,比如聯(lián)網(wǎng)獲取數(shù)據(jù),需要放到子線程去執(zhí)行
    new Thread(){
      @Override
      public void run () {
        super.run();
        //同步加載網(wǎng)絡(luò)數(shù)據(jù) 
        //加載數(shù)據(jù) 完畢后 關(guān)閉刷新狀態(tài) 切回主線程
        handler.postDelayed(new Runnable() {
          @Override
          public void run() {

            // 加載完數(shù)據(jù)設(shè)置為不刷新狀態(tài),將下拉進(jìn)度收起來(lái)
            swipeRefreshView.setRefreshing(false);
          }
        }, 100);
      }
    }.start();


  }
});

如有疑問(wèn)請(qǐng)留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論