EditText由ConstraintLayout中的软键盘切成两半

问题描述

我正在尝试创建一个聊天布局,所以我有一个带有EditText(使用圆角背景)和ImageButton来发送消息的recyclerview,但是当软键盘显示时,它会覆盖一点EditText和ImageButton的一部分。

我的android:windowSoftInputMode="adjustPan"中有AndroiManifest

我尝试过:

  • 使用android:windowSoftInputMode="adjustResize占用了我所有的BottomNavigationView(我不想要)
  • app:paddingBottomSystemWindowInsets="@{true}"放在我的ConstraintLayout上

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rv_support"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:transcriptMode="alwaysScroll"
            app:layoutManager="androidx.recyclerview.widget.linearlayoutmanager"
            app:layout_constraintBottom_toTopOf="@id/et_support"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:reverseLayout="true"
            tools:itemCount="3"
            tools:listitem="@layout/item_support_received" />

        <androidx.appcompat.widget.AppCompatEditText
            android:id="@+id/et_support"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@id/btn_support_send"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/rv_support"
            />

        <com.google.android.material.button.MaterialButton
            android:id="@+id/btn_support_send"
            android:layout_width="50dp"
            android:layout_height="50dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toEndOf="@id/et_support"
            app:layout_constraintTop_toBottomOf="@id/rv_support" />
    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>

在我的2张显示问题的图像下面:

enter image description here

enter image description here

解决方法

在您的recyclerview中添加底部填充“ 16”。

,

我通过以下方法找到了解决方法:

  1. 我已经在AndroidManifest中回到adjustPan
  2. 我在片段中添加了:
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
activity?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
}

override fun onViewCreated(view: View,savedInstanceState: Bundle?) {
    super.onViewCreated(view,savedInstanceState)
    // Extension method I've created to hide/show the bottomNav
    requireActivity().showBottomNavBar(false)
}

override fun onDestroyView() {
    super.onDestroyView()
    requireActivity().showBottomNavBar(true)
activity?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...