【问题标题】:Endless recycler view inside coordinatorLayoutcoordinatorLayout 内的无尽回收器视图
【发布时间】:2016-03-30 13:09:54
【问题描述】:

我们如何在 co-ordinator 布局中实现无限的 recyclerview?下面是我的布局。

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

任何帮助表示赞赏。谢谢。

【问题讨论】:

标签: android android-recyclerview android-coordinatorlayout endlessscroll android-nestedscrollview


【解决方案1】:

可以在 RecyclerView 上设置 OnScrollListener 以在 RecyclerView 上发生滚动事件时接收消息。

这里有一篇很好的文章如何实现这个....link

【讨论】:

    【解决方案2】:

    目前,您正在指示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);
    

    【讨论】:

    • 非常感谢。抱歉,我在没有阅读文档的情况下盲目地做出了这种错误。
    • 不用担心,它会发生。如果您认为它回答了您的问题,请务必勾选其中一个答案以“关闭”此问答。
    猜你喜欢
    • 1970-01-01
    • 2016-01-21
    • 2017-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-22
    • 2018-05-30
    • 1970-01-01
    相关资源
    最近更新 更多