Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Recyclerview inside Scrollview [duplicate]

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>
like image 954
AlgoCoder Avatar asked Dec 16 '15 14:12

AlgoCoder


2 Answers

You should use NestedScrollView instead. However you may need to write your own LayoutManager. Check out this SO Answer for more details

like image 98
ashkhn Avatar answered Nov 14 '22 21:11

ashkhn


  1. You need to use a custom layout manager to use recyclerview inside a scrollview.

  2. 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.

like image 4
Prashant Solanki Avatar answered Nov 14 '22 22:11

Prashant Solanki