SolvedPaginate Paginate with Nested Scroll View?

Hello, Marko. Thank you very much for the great lib. It's working great for me and you save me a lot of time and effort. I have two fragments. In the first one I have a recycle view only and I use Paginate and it works just great. In the second fragment I have a Nested scroll view like this:

<android.support.v4.widget.NestedScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/profileBg">

                <android.support.v7.widget.RecyclerView android:id="@+id/list"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:overScrollMode="never"
                    android:background="@color/profileBg"
                    xmlns:android="http://schemas.android.com/apk/res/android" />

            </LinearLayout>

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

        -------------------------------------------------------------------------------------------


        LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
        layoutManager.setAutoMeasureEnabled(true);

        adapter = new PostAdapter(mContext, posts, this);

        list.setLayoutManager(layoutManager);
        list.setNestedScrollingEnabled(false);
        list.addItemDecoration(new SpacesItemDecoration((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, mContext.getResources().getDisplayMetrics())));
        list.setAdapter(adapter);

        callbacks = new Paginate.Callbacks() {
            @Override
            public void onLoadMore() {
                loading = true;
                OFFSET += LIMIT;

                loadNextDataFromApi(OFFSET);
            }

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

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

        paginate = Paginate.with(list, callbacks)
                .setLoadingTriggerThreshold(8)
                .build();

I also tried without:

layoutManager.setAutoMeasureEnabled(true);
list.setNestedScrollingEnabled(false);

but the result is the same. I use the same logic in the two places but when it's in the nested scroll view scrolling becomes really slow and finally app just stop working. Without the Paginate it's work fine. Do you have any suggestions for this bug? Thank you very much!

Update: I set a break point and found that with NestedScrollView it enters in the callback infinity times even without scrolling. I hope this can help you finding the problem.

Update 2: The same problem when embedded in a CordinatorLayout.

22 Answers

✔️Accepted Answer

I had the same problem and found the solution.
Replace your NestedScrollView with LinearLayout like that:

<LinearLayout
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <android.support.v7.widget.RecyclerView
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:id="@+id/recycler_view"/>
</LinearLayout>

Don't forget to add app:layout_behavior="@string/appbar_scrolling_view_behavior" and android:layout_height="wrap_content" to attributes!

If you use RecyclerView inside NestedScrollView, layout manager can't measure it's height and set it infinite. So paginate will load data until all will be loaded even if you won't scroll the list.
With linear layout the height is measured and paginate will load data only if you scroll to the bottom of list.

Other Answers:

Is this issue solved?? I am also facing problems using pagination in NestedScrollView.

Any solution for this issue yet ?

@MarkoMilos do you have any progress on this?

@4lfant one might need a NestedScrollView if you have more than a RecyclerView on a Layout and you want them to scroll simultaneously.

In such scenario, how does one fix the pagination issue?

Related Issues:

9
Paginate Paginate with Nested Scroll View?
I had the same problem and found the solution Hello Marko Thank you very much for the great lib ...