question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Paginate with Nested Scroll View?

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:21 (2 by maintainers)

github_iconTop GitHub Comments

14reactions
4lfantcommented, Mar 3, 2017

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.

6reactions
DEV-NEPcommented, Nov 10, 2017

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

android - Pagination not work for the RecyclerView within ...
4 Answers 4 · 1. Set nested scrolling enabled false of recycler view. · 2. Add scroll listner to nested scrollview.
Read more >
NestedScrollView + Paginated Recyclerview Android · GitHub
NestedScrollView + Paginated Recyclerview Android. GitHub Gist: instantly share code, notes, and snippets.
Read more >
RecyclerView with NestedScrollView best practices and how ...
RecyclerView inside NestedScrollView is needed when there is a layout that contains some views and a small space for RecyclerView, ...
Read more >
Pagination - RecyclerView inside NestedScrollView - Android
I tried recyclerview inside a nestedScrollView using paging 3 library but it loads all the data, so I tried manually using the code...
Read more >
RecyclerView inside NestedScrollView not smooth
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...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found