如何在 ConstraintLayout 中垂直拉伸中间视图

How to stretch the middle view vertically in a ConstraintLayout

我的 XML 布局中有两个 TextInputLayouts 作为页眉和页脚,中间有一个 RecyclerView。我想要实现的是设置 RecyclerView 的高度以填充其他两个之间的区域。

我试过根据页眉和页脚设置 RecyclerView 的约束,并将 layout_height 设置为 0dp,但似乎有问题。 RecyclerView 在运行时被压缩为 0 像素。

这是我的代码:

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layoutDirection="ltr">

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/tilSearchTitle"
        android:layout_width="0dp"
        android:layout_height="60dp"
        android:background="@android:color/transparent"
        app:boxBackgroundColor="@android:color/transparent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:startIconDrawable="@drawable/ic_search">

        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:background="@android:color/transparent"
    </com.google.android.material.textfield.TextInputLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rvTitles"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layoutAnimation="@anim/layout_animation"
        android:paddingVertical="8dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toTopOf="@id/tilTitleValue"
        app:layout_constraintTop_toBottomOf="@id/tilSearchTitle" />

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/tilTitleValue"
        style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
        android:layout_width="0dp"
        android:layout_height="60dp"
        android:hint="@string/str23"
        app:boxBackgroundColor="@color/col_deep_bg"
        app:counterMaxLength="30"
        app:counterTextAppearance="@style/CounterStyle"
        app:expandedHintEnabled="false"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent">

        <com.zeroone.mooyrag.customui.MyTIET
            android:id="@+id/tietTitleValue"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:fontFamily="@font/iransans_med_fa"
            android:maxLines="1"
            android:scrollHorizontally="true"
            android:textAlignment="center"
            android:textSize="13sp" />
    </com.google.android.material.textfield.TextInputLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

Parent ConstraintLayout 高度应为 match_parent 而不是 wrap_content