Search code examples
android-recyclerviewandroid-scrollview

Scroll through the contents of a RecyclerView using an outer ScrollView


I have a RecyclerView located at the bottom of the inside of a vertical ScrollView. Now each RecyclerView item has an OnClickListener which "expands" the item's layout so that more details are shown. Now i noticed that when i have multiple item layouts expanded and i try to scroll up and down, logically the scroll is happening inside of the RecyclerView first thus :

  1. Scrolling at a lower speed than it would be if it was scrolling outside of the RecyclerView and inside of the ScrollView
  2. When you scroll upwards , the scrolling comes at a stop as you reach the top of the RecyclerView and then you need to scroll again to scroll through the rest of the ScrollView layout.

Furthermore, since the bottom part of the whole layout is occupied by the RecyclerView, in order to scroll upwards within the parent scrollview, you need to scroll to the top of the RecyclerView first, hit the top (where the indicator lights up) and then scroll upwards again. Is there any way that i can use the outer ScrollView to scroll through the RecyclerView items and their expanded layouts? Can i scroll through the main layout when i'm scrolling from within the recyclerview?


Solution

  • A NestedScrollView should be used instead of ScrollView, that is if you want to stick with scroll views in general.

    This approach is also explained here.

    Or you can replace the entire scroll view with a large RecyclerView. It can be vanilla or with Epoxy.