android RecyclerView未显示BottomSheetDialogFragment中的所有项

mwg9r5ms  于 2023-01-28  发布在  Android
关注(0)|答案(3)|浏览(272)

我有BottomSheetDialogFragment,它有一个输入字段和RecylcerView。ConstraintLayout的高度设置为match_parent,RecylcerView的高度为0dp。

<?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:id="@+id/bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

    <EditText
        android:id="@+id/et_enter_text"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:backgroundTint="@color/black"
        android:hint="Enter a city"
        android:layout_marginTop="20dp"
        android:textColor="@color/black"
        android:textColorHint="@color/black"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:ignore="Autofill,TextFields" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rv_result"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/et_enter_text"
        app:layout_constraintVertical_bias="0" />

</androidx.constraintlayout.widget.ConstraintLayout>

问题是当键盘打开时,RecyclerView只显示9个元素中的6个。

即使在android:windowSoftInputMode设置为adjustResize时,键盘仍与RecyclerView重叠。理想的行为是将RecyclerView底部约束附加到键盘顶部。
See screenshot
这是底页样式。

<style name="AppBottomSheetDialogTheme"
      parent="Theme.Design.Light.BottomSheetDialog">
      <item name="android:windowSoftInputMode">adjustResize</item>
</style>
anauzrmj

anauzrmj1#

ConstraintLayout更改为LinearLayout。我遇到了同样的问题,通过这种方法解决了。

pieyvz9o

pieyvz9o2#

请使用LinearLayout而不是约束布局,因为在约束布局内部进行回收器视图时,有时会出现异常行为
就像这样

<LinearLayout>
   ....
   <RecyclerView/>

</LinearLayout>
hkmswyz6

hkmswyz63#

这似乎是快速类似this的问题。
添加

app:layout_constrainedHeight="true"

到RecyclerView,就像它在1(https://stackoverflow.com/a/65124563/4334526) 2(https://stackoverflow.com/a/67834578/4334526)中建议的那样,确实对我起作用了

相关问题