I've found the answer myself.
You need to put the LinearLayout into a ScrollView and use wrap_content
as RecyclerView's layout_height
.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="@dimen/list_header"
android:background="@color/header"
android:gravity="center"
android:text="@string/find_friends__already_playing"
android:visibility="visible" />
<android.support.v7.widget.RecyclerView
android:id="@+id/in_app_friends"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:background="@color/white"/>
<TextView
android:layout_width="match_parent"
android:layout_height="@dimen/list_header"
android:background="@color/find_friends__header"
android:gravity="center"
android:text="@string/find_friends__invite_friends" />
<android.support.v7.widget.RecyclerView
android:id="@+id/friends_to_invite"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"/>
</LinearLayout>
</ScrollView>
Also there is a bug with with RecyclerView and wrap_content
so you have to use a custom layout manager. Check out this post: How do I make WRAP_CONTENT work on a RecyclerView
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…