How to use Recyclerview inside Scrollview
Solution 1
You should use NestedScrollView instead. However you may need to write your own LayoutManager. Check out this SO Answer for more details
Solution 2
You need to use a custom layout manager to use recyclerview inside a scrollview.
You can remove the scrollview and make a header item in the vertical recyclerview which contain the horizontal recyclerview.
Also you should not use a recyclerview inside a scrollview. So think the second approach will be better.
Also you can can use Snap-RecyclerView-Utils. It has a linear layout manager for recyclerview inside a scroll view and an adapter which can help you make a header containing you horizontal recyclerview.
Solution 3
ScrollView
can only have one child.
Remove your RelativeLayout
and try again.
Apart from that android:layout_height
in ScrollView
should be set to wrap_content
Additionally I'm not quite sure, if it works, since in the Docs it is stated that
You should never use a ScrollView with a ListView, because ListView takes care of its own vertical scrolling. Most importantly, doing this defeats all of the important optimizations in ListView for dealing with large lists, since it effectively forces the ListView to display its entire list of items to fill up the infinite container supplied by ScrollView.
Maybe a NestedScrollView
works since it is for
NestedScrollView is just like ScrollView, but it supports acting as both a nested scrolling parent and child on both new and old versions of Android. Nested scrolling is enabled by default.
AlgoCoder
Updated on August 12, 2022Comments
-
AlgoCoder over 1 year
I'm trying to show horizontal recyclerview items and vertical recyclerview items inside an ScrollView
Scrollview didn't work even If i use android:fillViewport="true"
<ScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> //Horizontal Recyclerview items <RecyclerView android:layout_width="match_parent" android:layout_height="wrap_content"> </RecyclerView> //vertical Recyclerview items <RecyclerView android:layout_width="match_parent" android:layout_height="match_parent"></RecyclerView> </LinearLayout> </ScrollView>
-
AlgoCoder over 8 yearsthanks for the reply, but that solution is buggy