《android recyclerview的簡單使用》

來源:互聯網
上載者:User

標籤:

首先是主要布局

<android.support.v4.widget.SwipeRefreshLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/swipeRefreshLayout"android:layout_width="match_parent"android:layout_height="match_parent">    <android.support.v7.widget.RecyclerView        android:id="@+id/recylerView"        android:layout_width="wrap_content"        android:layout_height="wrap_content"></android.support.v7.widget.RecyclerView></android.support.v4.widget.SwipeRefreshLayout>

然後是擷取控制項以及設定監聽

findViewById......//設定下拉重新整理swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {        @Override        public void onRefresh() {            if(isrefreshing){//判斷是否正在重新整理                Log.d(TAG,"ignore manually update!");            } else{                 do.......            }        }    });

說了下拉重新整理,那麼就有上拉載入更多,其實個人覺得上拉載入更多RecyclerView以及SwipeRefreshLayout都沒有做得很好,也是這個控制項用起來不是很舒服的地方。簡單的介紹一種方式

recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {            @Override            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {                super.onScrolled(recyclerView, dx, dy);                int lastVisibleItem = ((LinearLayoutManager) mLayoutManager).findLastVisibleItemPosition();                int totalItemCount = mLayoutManager.getItemCount();                //lastVisibleItem >= totalItemCount - 4 表示剩下4個item自動載入,各位自由選擇                // dy>0 表示向下滑動                if (lastVisibleItem >= totalItemCount - 4 && dy > 0) {                    if(isLoadingMore){                         Log.d(TAG,"ignore manually update!");                    } else{                         loadPage();//這裡多線程也要手動控制isLoadingMore                        isLoadingMore = false;                    }                }            }        });

總結:

    1、新控制項用起來是很舒服,但是很多功能沒有全部書寫好

    2、期望官方解決上拉載入更多的問題

《android recyclerview的簡單使用》

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.