android - windowSoftInput 隐藏recycleview中的项目
问题描述
我正在创建一个聊天应用程序,到目前为止它看起来像这样:
我开始输入的那一刻,它隐藏了最后两项,看起来像(edittext 隐藏了 g、h 消息):
我的 XML 文件如下所示:
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ChatActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_Messages"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/ib_Send"
style="?android:borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:adjustViewBounds="true"
android:src="@drawable/ic_location_on_black_24dp"
app:layout_constraintHeight_percent="0.1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<EditText
android:id="@+id/et_Message"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:hint="enter message here"
android:backgroundTint="@color/colorLightPurple"
android:inputType="textMultiLine|textPersonName"
app:layout_constraintHeight_percent="0.1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/ib_Send"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
我已经添加到我的清单中android:windowSoftInputMode="adjustPan"
有没有一种方法可以确保我的recycleview 将始终显示最新消息/确保edittext 不会隐藏?
谢谢
解决方案
使用相对和线性布局的组合,然后在recyclerview 中使用marginBottom。希望你能找到它。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ChatActivity">
<include
android:id="@+id/chat_toolbar"
layout="@layout/app_bar_layout">
</include>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/private_messages_list_of_users"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/chat_toolbar"
android:layout_above="@+id/chat_linear_layout"
android:layout_marginBottom="6dp"
>
</androidx.recyclerview.widget.RecyclerView>
<RelativeLayout
android:id="@+id/chat_linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:background="@android:color/background_light"
android:orientation="horizontal"
>
<ImageButton
android:id="@+id/send_files_btn"
android:layout_width="60dp"
android:layout_height="50dp"
android:src="@drawable/ic_attach_file_black_24dp"
android:layout_alignParentStart="true"
android:backgroundTint="@android:color/white"
/>
<EditText
android:id="@+id/input_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="type message here..."
android:padding="15dp"
android:maxLines="5"
android:layout_toEndOf="@+id/send_files_btn"
android:layout_toStartOf="@+id/send_message_btn"
/>
<ImageButton
android:id="@+id/send_message_btn"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:src="@drawable/send_message"
android:layout_alignParentEnd="true"
android:backgroundTint="@android:color/white"
/>
</RelativeLayout>
</RelativeLayout>
看看我上面的例子......
推荐阅读
- javascript - 使用 HTML5 Api 拖放后,两个事件侦听器之一将从被拖动和替换的项目中删除
- azure-functions - 触发器不再冷启动 Azure Function (Consumption)
- postgresql - B 树的填充因子。为什么在右侧扩展索引而不是在其他情况下(创建索引期间除外)时尊重填充因子?
- javascript - 在基于 rowIndex 和 columnIndex 的角度垫表中插入数据
- python - Python中基于二进制列查找和删除重复项
- arrays - 你可以切片一个 numpy 数组,然后将切片索引设置为等于另一个相同长度的 numpy 数组吗?
- jenkins - 詹金斯:如何让特定的构建保持更长的时间?
- ruby-on-rails - 如何向 ActionMailer::MessageDelivery 添加一个方法,以便deliver_now 用于开发,deliver_later 用于生产
- reactjs - 使用 useState 将对象推入状态数组时出现打字稿错误
- flutter - Flutter with Canvas 中的圆波动画 - 图表