I have a Recyclerview with GridLayoutManager whose child items may have a vertical RecyclerView inside it. Here is the screenshot:
I have created adapters for this scenario. It shows it properly but internal Recyclerview is not scrolling no matter how many items are inside it. Can anyone suggest how to make internal and main RecyclerViews scroll?
To be able to scroll through a vertical list of items that is longer than the screen, you need to add a vertical scrollbar. Inside RecyclerView , add an android:scrollbars attribute set to vertical .
NestedScrollView is just like ScrollView, but it supports acting as both a nested scrolling parent and child. In your case you have to define your own scrolling behaviour.
It's pretty simple, simply set the RecyclerView 's height to wrap_content . That's right.
In the practical on scrolling views, you use ScrollView to scroll a View or ViewGroup . ScrollView is easy to use, but it's not recommended for long, scrollable lists. RecyclerView is a subclass of ViewGroup and is a more resource-efficient way to display scrollable lists.
I found the solution. I just had to disable the touch event of the parent in case Recyclerview receives touch event. Here is the code snippet that worked for me:
RecyclerView.OnItemTouchListener mScrollTouchListener = new RecyclerView.OnItemTouchListener() {
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
int action = e.getAction();
switch (action) {
case MotionEvent.ACTION_MOVE:
rv.getParent().requestDisallowInterceptTouchEvent(true);
break;
}
return false;
}
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
}
@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}
};
recyclerView.addOnItemTouchListener(mScrollTouchListener);
I found the answer here: Recyclerview inside Scrollview
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With