I have two simple recycler views that I want to show directly below each other. Here is my layout:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
layout="@layout/drawer_view_header"
android:id="@+id/navigation_header"/>
<android.support.v7.widget.RecyclerView
android:layout_below="@id/navigation_header"
android:id="@+id/friends_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.v7.widget.RecyclerView
android:layout_below="@id/friends_list"
android:id="@+id/followers_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
I have my navigationHeader
above my first recycler view called friends_list
which works fine, and I can see the friends_list
recycler view which has android:layout_height="wrap_content"
but the followers_list
recycler view doesn't seem to show even though all the contents of my friends_list
is all shown. Any ideas why it is not showing up? Thanks!
While the above answers do work they don't preserve the wrap content behavior of recycler view for that you need to use a NestedScrollView
.
For eg you need to do something like this:-
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
layout="@layout/drawer_view_header"
android:id="@+id/navigation_header"/>
<android.support.v7.widget.RecyclerView
android:layout_below="@id/navigation_header"
android:id="@+id/friends_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.v7.widget.RecyclerView
android:layout_below="@id/friends_list"
android:id="@+id/followers_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
Or you may also use a LinearLayout
with vertical alignment in your NestedScrollView
.
*Note:- this will only work with recycler view above 23.2.0
compile 'com.android.support:recyclerview-v7:23.2.0'