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.