首页 > 解决方案 > 放入 NestedScrollView 时,列表页面 RecyclerView 无限滚动不起作用

问题描述

我已经采取了两个recyclerviews,因为我必须显示两个列表,其中一个是水平列表,另一个是具有无限滚动的垂直列表,对于滚动两个列表,我已将它们添加到nestedScrollView中,但垂直列表的无限滚动不起作用,有向下滚动时第一次加载项目后的分页逻辑然后调用api然后加载列表中的项目

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


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">


        <LinearLayout
            android:id="@+id/llRecentlyBought"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:orientation="vertical"
            android:visibility="gone"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <TextView
                android:id="@+id/txtVRecentlyBought"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/bg_grey_color"
                android:padding="10dp"
                android:text="@string/recently_bought"
                android:textSize="@dimen/font_s_ize_levelone_signup" />

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerRecentlyBought"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:nestedScrollingEnabled="false"
                android:paddingStart="@dimen/padding_home_1"
                android:paddingEnd="@dimen/padding_home_1"
                android:scrollbars="none"
                android:focusable="false"
                android:focusableInTouchMode="true"
                app:layout_behavior="@string/appbar_scrolling_view_behavior" />

            </LinearLayout>


            <android.support.v7.widget.RecyclerView
                android:id="@+id/products_in_gridView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/llRecentlyBought"
                android:layout_alignParentStart="true"
                android:layout_gravity="top"
                android:layout_marginTop="5dp"
                android:background="@android:color/white"
                android:descendantFocusability="blocksDescendants"
                android:fadingEdge="none"
                android:paddingStart="@dimen/padding_home_1"
                android:paddingEnd="@dimen/padding_home_1"
                android:paddingBottom="@dimen/padding_home_1"
                android:scrollbars="none"
                android:focusable="false"
                android:focusableInTouchMode="true"    
                app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

           </RelativeLayout>

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







BaseAttacher mBaseAttacher = Mugen.with(productsInGridRecyclerView, new MugenCallbacks() {
            @Override
            public void onLoadMore() {
                if (indexOfCurrentPage < TOTAL_PAGE_AVAILABLE) {
                    indexOfCurrentPage += 1;
                    // loadNextPage(indexOfCurrentPage);


                    if (isLastPage == false) {
                        loadNextPage(indexOfCurrentPage);
                    } else if (isLastPage == true) {
                        //   Toast.makeText(getActivity(), "No more products", Toast.LENGTH_SHORT).show();
                        Toast.makeText(getActivity(), getResources().getString(R.string.txt_no_product_found), Toast.LENGTH_SHORT).show();
                    }

                }
            }

            @Override
            public boolean isLoading() {
                return isLoading;
            }

            @Override
            public boolean hasLoadedAllItems() {
                return false;
            }
        }).

                start();
        mBaseAttacher.setLoadMoreEnabled(true);
        mBaseAttacher.setLoadMoreOffset(2);

上面是垂直列表的baseattacher,当我向下滚动时它没有被调用,没有nestedscrollview它的工作帮助我在nestedscrollview中无限滚动列表

使用的库https://github.com/vinaysshenoy/mugen

标签: javaandroid-recyclerviewinfinite-scrollandroid-nestedscrollview

解决方案


不需要nestedscrollview 我刚刚将 app:layout_behavior="@string/appbar_scrolling_view_behavior" 添加到父布局中它可以工作!


推荐阅读