RecyclerView高度在筛选列表时发生更改



我在BottomSheetFragment中有一个RecyclerView,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/BottomSheet"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/search_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:boxBackgroundMode="filled"
app:boxStrokeWidth="0dp"
app:boxStrokeWidthFocused="0dp"
app:endIconMode="custom"
app:boxCornerRadiusBottomStart="16dp"
app:boxCornerRadiusBottomEnd="16dp"
app:boxCornerRadiusTopEnd="16dp"
app:boxCornerRadiusTopStart="16dp"
app:endIconDrawable="@drawable/ic_baseline_search_24"
app:boxStrokeColor="@color/primary" >
<com.google.android.material.textfield.TextInputEditText
android:maxLines="1"
android:maxLength="25"
android:inputType="textCapSentences"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
</com.google.android.material.textfield.TextInputLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>

每当我过滤列表时,由于RecyclerViewBottomSheetFragment收缩到较小的高度。如何保持列表的高度?

如果有人想知道我是如何解决这个问题的。我设法在线性布局的末尾添加了一个简单的空视图,其高度和宽度与父视图相匹配。

最新更新