1

In my application, I am using RecyclerView inside NestedScrollView and also, I am implementing pagination with this. I am attaching my piece of code below for implementing nested scroll view with pagination.

I have a large no data attaching to recyclerview, therefore, this data takes a lot of time attaching which effects the smooth scrolling of the list.

I had only a recylerview which had simple scrolling issues, wasn't smooth, but still pagination was working fine. I inserted my recyclerview inside the nestedscrollview, the scrolling becomes smooth only for the first page. But when pagination is called, the scrolling gets effected very badly.

When the page number increments, the scrolling goes from bad to worst.

Let me show my code that I used for nested view scrolling and pagination.

home.xml:

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

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

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

And this is my Fragment Class.java:

@BindView(R.id.nestedScroll)
NestedScrollView nestedScroll;

private int currentPage = 0;

nestedScroll.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
            @Override
            public void onScrollChanged() {

                View view = (View) nestedScroll.getChildAt(nestedScroll.getChildCount() - 1);
                int diff = (view.getBottom() - (nestedScroll.getHeight() + nestedScroll.getScrollY()));

                if (diff == 0) {
                    if (blnCheckREsult == false) {
                        blnCheckREsult = true;
                        if (ConnectivityReceiver.isConnected()) {
                            currentPage++;
                            getHomeData(currentPage);

                        } else {
                            Toast.makeText(activity, "Please check your internet connection", Toast.LENGTH_SHORT).show();
                        }
                    }

                }

            }
        });

I want to implement smooth scrolling even when the adapter takes time while binding data to the view holder. But the scrolling becomes really slow when setting data inside the adapter.

Or If I am missing something else, please correct me.

Thanks in advance.

Phantômaxx
  • 37,352
  • 21
  • 80
  • 110
Sarthak Sharma
  • 127
  • 3
  • 10
  • remove your nested scroll view if not needed. and implement pagination with recycler view – Rajasekaran M May 15 '19 at 13:38
  • At first, the recyclerview was simple. I was not using any nested scrollview, therefore scrolling was not that good. But after implementing nested scroll, the scrolling is smooth but gets effected while binding data to views, therefore it takes time. – Sarthak Sharma May 15 '19 at 13:43
  • Actually if you are using recycler view inside nested scroll view,it's won't re-use the views and it's created views for your count. so it's will take time when you update data for items. – Rajasekaran M May 15 '19 at 13:47
  • may be your `onBind()` method doing long running process. so can you add it with your question? – Rajasekaran M May 15 '19 at 13:49
  • Yes the 'onBindViewHolder()' is doing some heavy task. I have even tried putting 'notifyDataSetChanged()' inside another thread as well. But that had no success. – Sarthak Sharma May 15 '19 at 14:03
  • add your adapter code to question. – Rajasekaran M May 15 '19 at 14:23

1 Answers1

0

Try set this in your RecyclerView: rv.setNestedScrollingEnabled(false); before set adapter.

Henrique Monte
  • 1,262
  • 1
  • 15
  • 21
  • I already did that. Apart from this I also tried ``ViewCompat.setNestedScrollingEnabled(homeRecyclerView, false);``. But didn't had any success. – Sarthak Sharma May 16 '19 at 05:04