在“回收者视图”下方的“回收者视图”,但不超过一半

时间:2018-07-05 10:15:16

标签: android android-layout android-recyclerview android-linearlayout

我想创建一个包含两个列表(RecyclerView)的页面,每个列表都有一个标头(TextView),一个从前一个末尾开始。但是我希望每个人最多有一半的页面。因此,在第一个列表包含一个项目的情况下,第二个列表将直接放置在下面,如果第一个列表很长,它将仅占据页面的一半,而第二个列表将从后一半开始。我希望每个人都占一半

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
    android:id="@+id/list_one"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"/>

<android.support.v7.widget.RecyclerView
    android:id="@+id/list_two"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"/>
</LinearLayout>

1 个答案:

答案 0 :(得分:0)

尝试这个

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