簡體   English   中英

coordinatorLayout 中無盡的回收器視圖

[英]Endless recycler view inside coordinatorLayout

我們如何在協調器布局中實現無盡的回收器視圖? 下面是我的布局。

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/ParentTownMaterialTheme.AppBarOverlay">

// Inside linear layout child views are there

        <LinearLayout
            android:id="@+id/linear_scroll_enter"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            app:layout_scrollFlags="scroll|enterAlways"/>

 </android.support.design.widget.AppBarLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/response_lv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/linear_scroll_enter"
        android:background="@android:color/white"
        android:clipToPadding="false"
        android:divider="@android:color/transparent"
        android:paddingBottom="6dp"
        android:paddingTop="6dp"
        android:scrollbars="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</android.support.design.widget.CoordinatorLayout>

無盡的 recyclerview 在這里工作,但順序相反。 如 :

item 10
item 9
item 8
item 7
item 6

----------
LOAD MORE
----------

item 5
item 4
item 3
item 2
item 1

它應該是這樣的:

 item 1
    item 2
    item 3
    item 4
    item 5

   -----------
    LOAD MORE
   -----------

    item 6
    item 7
    item 8
    item 9
    item 10

這是java代碼:

response_lv.setHasFixedSize(false);
        final LinearLayoutManager mLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, true);
        response_lv.setLayoutManager(mLayoutManager);
        response_lv.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));
        response_lv.setItemAnimator(new DefaultItemAnimator());
        response_lv.setAdapter(profileFragmentRecyclerAdapter);

        response_lv.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                if (dy > 0) {
                    if ((mLayoutManager.getChildCount() + mLayoutManager.findFirstVisibleItemPosition()) >= mLayoutManager.getItemCount()) {
                        Log.d("TAG", "End of list");

                        totalItemCount = mLayoutManager.getItemCount();
                        lastVisibleItem = mLayoutManager.findLastVisibleItemPosition();

                        if (!isLoading && totalItemCount <= (lastVisibleItem + visibleThreshold)) {
                            isLoading = true;
                            current_page++;
                            setLoadingView();
                            new ProfileAsyncTask().execute();
                        }
                    }
                }
            }
        });

任何幫助表示贊賞。 謝謝。

可以在 RecyclerView 上設置 OnScrollListener 以在該 RecyclerView 上發生滾動事件時接收消息。

這是一篇非常好的文章如何實現這一點....l墨水

目前,您正在指示LayoutManager反轉其布局(這就是第三個/布爾參數的用途)。 因此,順序顛倒了。

你會想要改變:

final LinearLayoutManager mLayoutManager = 
    new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, true);

到:

final LinearLayoutManager mLayoutManager = 
    new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);

這與僅調用相同:

final LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM