我有一个ConstraintLayout,其中包含一个appBar(包含一个工具栏),两个片段(每个包含一个RecyclerView)和一个位于底部的按钮。
我想做的是将布局的高度包装在RecyclerViews的大小上。如下图所示,无论列表大小如何,每个Recyclerview的高度都相等。
这是我的布局
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/template_grey_light"
tools:context=".presentation.ui.activity.MainActivity">
<include
android:id="@+id/AppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/fragmentTop"
app:layout_constraintVertical_chainStyle="packed"
layout="@layout/app_bar" />
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragmentTop"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/AppBar"
app:layout_constraintBottom_toTopOf="@+id/fragmentBottom"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragmentBottom"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/fragmentTop"
app:layout_constraintBottom_toTopOf="@+id/shuffleButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
<Button
android:id="@+id/shuffleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:background="@color/template_love_red"
android:text="Go!"
android:layout_marginBottom="20dp"
app:layout_constraintTop_toBottomOf="@+id/fragmentBottom"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
我知道我在height属性上使用0dp,这使它的高度相等,但是如果我不这样做,则所有内容都会在顶部重叠。关于如何使它起作用的任何想法吗?