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

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

成都創(chuàng)新互聯(lián)服務(wù)項(xiàng)目包括蕪湖縣網(wǎng)站建設(shè)、蕪湖縣網(wǎng)站制作、蕪湖縣網(wǎng)頁(yè)制作以及蕪湖縣網(wǎng)絡(luò)營(yíng)銷策劃等。多年來(lái),我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,蕪湖縣網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到蕪湖縣省份的部分城市,未來(lái)相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!

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 >

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

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);

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

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

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

    // 開(kāi)始刷新,設(shè)置當(dāng)前為刷新?tīng)顟B(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īng)顟B(tài) 切回主線程
        handler.postDelayed(new Runnable() {
          @Override
          public void run() {

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


  }
});

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

網(wǎng)站題目:AndroidRecyclerView設(shè)置下拉刷新的實(shí)現(xiàn)方法
鏈接分享:http://bm7419.com/article44/ijpshe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、靜態(tài)網(wǎng)站網(wǎng)站設(shè)計(jì)、定制網(wǎng)站網(wǎng)站營(yíng)銷、外貿(mào)建站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

營(yíng)銷型網(wǎng)站建設(shè)