【问题标题】:Recycler View below Recycler View, but not after halfRecycler View 在 Recycler View 下面,但不是在一半之后
【发布时间】:2018-07-05 10:15:15
【问题描述】:

我想要一个包含两个列表(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>

【问题讨论】:

  • 您不能对其内容进行回收利用。由于滚动行为是确定内容大小是否大于回收站视图大小

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


【解决方案1】:

试试这个

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-11
    • 2018-06-23
    • 1970-01-01
    • 1970-01-01
    • 2015-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多