Search code examples
androidandroid-recyclerviewandroid-support-librarynested-listsgridlayoutmanager

ScrollView with nested RecyclerViews and bidirectional scroll


I would like to achieve the result shown in the gif below

enter image description here

Two list views which scroll vertically together and one of them can also scroll horizontally to show more contents.

I saw it in a card from Google Discover and I would like to apply it in one of my projects. I could try to implement it by myself but since it is used by Google maybe it is already available, for instance as a material design component or so.

I couldn't find anything similar so far.


Solution

  • Found a solution in the end using this layout.

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:overScrollMode="never">
    
       <LinearLayout
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:orientation="horizontal"
           android:weightSum="2">
    
           <android.support.v7.widget.RecyclerView
               android:id="@+id/left_recycler_view"
               android:layout_width="0dp"
               android:layout_height="wrap_content"
               android:nestedScrollingEnabled="false"
               android:layout_weight="1" />
    
           <HorizontalScrollView
               android:layout_width="0dp"
               android:layout_height="wrap_content"
               android:layout_weight="1">
    
               <android.support.v7.widget.RecyclerView
                   android:id="@+id/right_recycler_view"
                   android:layout_width="wrap_content"
                   android:nestedScrollingEnabled="false"
                   android:layout_height="wrap_content" />
    
           </HorizontalScrollView>
    
       </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
    

    Both the recycler view have a simple LinearLayoutManager

    android:nestedScrollingEnabled="false" is available only since API 21 so in other cases it needs to be set by code.