ConstraintLayout & FrameLayout wrap_content然后 FrameLayout 显示一半内容



我不知道为什么FrameLayout在ConstraintLayout,都使用wrap_content,然后在RecycleView的最后一个项目只是显示一半的内容。如果我删除frameayout,直接使用recycleview,它可以工作!

<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/finance_bg_book_list_dialog">

<TextView
android:id="@+id/tvToolbarTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/finance_bg_book_list_toolbar"
android:drawablePadding="10dp"
android:padding="14dp"
android:text="@string/finance_book"
android:textColor="@android:color/white"
android:textSize="?fontSizeLarge"
app:drawableStartCompat="@drawable/finance_ic_toolbar_shelf"
app:layout_constraintBottom_toTopOf="@+id/vulturLayout"
app:layout_constraintTop_toTopOf="parent"/>

<FrameLayout
android:id="@+id/vulturLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constrainedHeight="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvToolbarTitle">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_contentCode="successful"/>
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

在textview上需要一些水平约束。示例:app:layout_constraintStart_toStartOf=

我建议您为RecyclerView的高度设置一个尺寸。如果您使用FrameLayoutwrap_content的高度,您的RecyclerView将不能滚动,它将显示一半的项目在最后基于屏幕大小

最新更新