Scolling with several RecyclerViews in layout

I created a layout that has two RecyclerViews. One scrolls horizontally and the other scrolls vertically. I can correctly scroll inside each RecyclerView, but the page as a whole will not scroll, i.e. The top of the RecyclerView remains at the top and the bottom at the bottom, as both are fixed in position.

Below is my xml layout:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> <EditText android:id="@+id/search" android:layout_width="fill_parent" android:layout_height="50dp" android:hint="Search Dramas" android:textSize="16sp" android:paddingLeft="10dp" android:gravity="center" android:textColor="@color/dark_grey" android:textColorHint="@color/dark_grey" android:background="@drawable/border_bottom"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/border_bottom_background_black" android:textColor="@color/white" android:padding="10dp" android:text="Most Watched"/> <!-- A RecyclerView to display horizontal list --> <android.support.v7.widget.RecyclerView android:id="@+id/featured" android:scrollbars="none" android:layout_width="fill_parent" android:layout_height="240dp" android:paddingLeft="0dp" android:paddingRight="15dp" android:paddingTop="15dp" android:paddingBottom="25dp" android:background="@color/black"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/border_bottom_backgroundless" android:textColor="@color/dark_grey" android:padding="10dp" android:text="All Dramas"/> <!-- A RecyclerView to display vertical list --> <android.support.v7.widget.RecyclerView android:id="@+id/pick_item" android:scrollbars="vertical" android:layout_width="fill_parent" android:layout_height="match_parent"/> </LinearLayout> 

How activity looks

+6
source share
2 answers

I managed to solve the problem by placing everything inside the ScrollView , and then setting the height of the vertical RecyclerView manually / programmatically.

 <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/scrollView"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <EditText android:id="@+id/search" android:layout_width="fill_parent" android:layout_height="50dp" android:hint="Search Dramas" android:textSize="16sp" android:paddingLeft="10dp" android:gravity="center" android:textColor="@color/dark_grey" android:textColorHint="@color/dark_grey" android:background="@drawable/border_bottom"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/border_bottom_background_black" android:textColor="@color/white" android:padding="10dp" android:text="Most Watched"/> <!-- A RecyclerView to display horizontal list --> <android.support.v7.widget.RecyclerView android:id="@+id/featured" android:scrollbars="none" android:layout_width="fill_parent" android:layout_height="240dp" android:paddingLeft="0dp" android:paddingRight="15dp" android:paddingTop="15dp" android:paddingBottom="25dp" android:background="@color/black"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/border_bottom_backgroundless" android:textColor="@color/dark_grey" android:padding="10dp" android:text="All Dramas"/> <!-- A RecyclerView to display list --> <android.support.v7.widget.RecyclerView android:id="@+id/pick_item" android:paddingBottom="20dp" android:scrollbars="vertical" android:layout_width="fill_parent" android:layout_height="match_parent" android:minHeight="840dp"/> </LinearLayout> </ScrollView> 

Programmatically adjust the height of the RecyclerView:

 LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); // calculate height of RecyclerView based on child count params.height=1150; // set height of RecyclerView recyclerView.setLayoutParams(params); 
+7
source

RecyclerView only got (still limited) nested scroll support in version 22.2.0 - my first suggestion would be to try.

The only view that fully supports nested scrolling is NestedScrollView (you can see this, noting that it implements both NestedScrollingChild and NestedScrollingParent ) and has been added to the support version v.2 version 22.1. 0 (slightly improved in 22.2.0). If you only have one horizontal RecyclerView as the topmost element in the vertical RecyclerView , you can instead replace it with a NestedScrollView that contains a LinearLayout with a horizontal RecyclerView , followed by your vertical RecyclerView .

+3
source

Source: https://habr.com/ru/post/989306/


All Articles