0

I have a recyclerView inside a NestedScrollView. I know this is not a good practice, but I need a listener for the scroll.

The listener consists on notify when the user reached the final of the recyclerView. This have a gridLayoutManager with 3 grids and the number of rows visible depends of the size of the screen.

Everything works but the smoothScroll.

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

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

This is how is working my app.

Example screen gif

Vamsi Smart
  • 928
  • 9
  • 16
BlueSeph
  • 543
  • 1
  • 8
  • 25

1 Answers1

0

Try this.. recylerView.setNestedScrollingEnabled(false); in your activity.... Edit To notify user if he reached end..use this

recyclerView.addOnScrollListener(new      RecyclerView.OnScrollListener() { 

   @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy)
   {  

  LinearLayoutManager layoutManager=LinearLayoutManager.class.cast(recyclerView.getLayoutManager()); 
   int totalItemCount = layoutManager.getItemCount();

   int lastVisible = 
    layoutManager.
    findLastVisibleItemPosition();                     boolean
 endHasBeenReached 
 = lastVisible + 5 
    >= totalItemCount;
 if (totalItemCount > 0 && endHasBeenReached) 

 { //you have reached to the bottom of your recycler view } } });
Santanu Sur
  • 10,997
  • 7
  • 33
  • 52
  • If I do that my listener is disabled. I need that listener to update the items of the recyclerView when the user get to the end of it. – BlueSeph Feb 19 '18 at 18:03
  • i have updated the code..add scroll listener to the recyclerview..when last item visible `notify user` or fetch the next items.. – Santanu Sur Feb 19 '18 at 18:05
  • test it and let me know if you have any other problems – Santanu Sur Feb 19 '18 at 18:09
  • 1
    it worked!, Thanks. I'm using Kotlin and I had problems to translate LinearLayoutManager.class.cast(recyclerView.getLayoutManager()), but I translated to LinearLayoutManager::class.java.cast(recyclerView.layoutManager) and worked. Thanks to this I'm not using a NestedScrollView anymore. – BlueSeph Feb 19 '18 at 18:27