android - RecyclerView 不会填满剩余空间(ConstraintLayout)
问题描述
我试图让我的 RecyclerView 填补两个视图之间的空白,一个位于布局的顶部,另一个位于底部。我尝试将 RecyclerView 的高度设置为 0dp 并将约束设置在下方,但由于某种原因,RecyclerView 根本没有呈现。适配器实际上确实包含数据,如果我将 RecyclerView 的高度设置为任意值,例如 200dp,那么它的行会按预期显示。
app:layout_constraintTop_toBottomOf="@id/label_realm_filter"
app:layout_constraintBottom_toTopOf="@id/btn_realm_filter_apply"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
这是我的其余布局:
<androidx.cardview.widget.CardView
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="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="8dp"
android:background="@drawable/bg_white_rounded_edges"
app:cardCornerRadius="6dp"
app:cardElevation="6dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/label_realm_filter"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp"
android:layout_marginTop="24dp"
android:layout_marginRight="8dp"
android:text="@string/realm"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/btn_realm_filter_close"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/btn_realm_filter_close"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginTop="24dp"
android:layout_marginRight="24dp"
android:src="@drawable/ic_close"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list_realm_filter"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="18dp"
android:layout_marginBottom="18dp"
app:layout_constraintTop_toBottomOf="@id/label_realm_filter"
app:layout_constraintBottom_toTopOf="@id/btn_realm_filter_apply"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<TextView
android:id="@+id/btn_realm_filter_apply"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp"
android:layout_marginTop="16dp"
android:layout_marginRight="24dp"
android:layout_marginBottom="24dp"
android:clickable="true"
android:focusable="false"
android:focusableInTouchMode="true"
android:gravity="right"
android:text="@string/apply"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
感谢您的时间。
解决方案
推荐阅读
- twitter-bootstrap - 当我将传单地图放在 Bootstrap 5 模态中时,它变得疯狂
- postgresql - 递归与分离表的性能
- javascript - 如何为 AWS DocumentClient javascript SDK 设置默认超时
- r - 从R中的列表中对矩阵元素进行替换采样
- visual-studio-code - 在 Windows 7 上的 VS Code 上打开表情符号选择器的快捷键不起作用
- javascript - 使用类在 svelte 上首次设置超时后应用程序崩溃
- timer - oidc-client addAccessTokenExpiring 定时器在哪里/如何设置?
- python - 是否可以让 SQL Alchemy 数据库模型指向不同模型的属性,这样当一个模型的数据发生变化时,另一个模型的数据也会发生变化?
- webpack - 缺少变量的 SCSS 的 Mixin Webpack 错误
- rust - 获取 rust 的商和余数 (DIVMOD) 的函数是什么?