android - RecyclerView 不显示 BottomSheetDialogFragment 内的所有项目
问题描述
我有带有输入字段和 RecyclerView 的 BottomSheetDialogFragment。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 底部约束附加到键盘顶部。
这是底页的样式。
<style name="AppBottomSheetDialogTheme"
parent="Theme.Design.Light.BottomSheetDialog">
<item name="android:windowSoftInputMode">adjustResize</item>
</style>
解决方案
请使用 LinearLayout 而不是约束布局,因为有时在约束布局内的回收器视图时会出现奇怪的行为
推荐阅读
- mysql - 添加降序条件后sql查询不起作用
- apache-spark - Spark 数据集分区与 cassandra 创建一大块镶木地板文件以及许多小文件
- asp.net - 如何将图像从 Ionic 3 应用程序上传到内置 ASP.NET CORE 的网络服务器?
- java - KeyListener 在带有 Netbeans 的 Java 中不起作用
- python - 当我使用 numpy.array() 处理 'list' 时如何处理?
- ios - 未调用 UITextView 委托方法
- javascript - ES6 减少返回 1 个数组项而不是 2 个
- jquery - 使用 Select2.js 搜索文本和 id
- html - 遵循 BEM 约定编写 css flex 代码的最佳方法是什么?
- c - Linux-内存不足