Android 键盘覆盖recyclerView下的edittext

Android Keyboard covers edittext under recyclerView

<?xml version="1.0" encoding="utf-8"?>
<layout 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">

<data>

    <variable
        name="viewModel"
        type="app.redtaxi.client.views.chat.ChatViewModel" />
</data>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:isScrollContainer="true"
        android:scrollbars="none">


        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/lesser_white"
            android:gravity="bottom"
            android:paddingTop="25dp"
            tools:context=".views.chat.ChatActivity">


            <RelativeLayout
                android:layout_width="42dp"
                android:layout_height="42dp"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                android:layout_marginStart="10dp"
                android:layout_marginTop="10dp"
                android:layout_marginBottom="16dp"
                android:background="@drawable/round_shape"
                android:clickable="true"
                android:elevation="4dp"
                android:focusable="true"
                android:onClick="@{() -> viewModel.onBackBtnClicked()}">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_centerInParent="true"
                    android:padding="10dp"
                    android:src="@drawable/ic_back_arrow" />

            </RelativeLayout>


            <ImageView
                android:layout_width="42dp"
                android:layout_height="42dp"
                android:layout_alignParentTop="true"
                android:layout_alignParentEnd="true"
                android:layout_marginTop="10dp"
                android:layout_marginEnd="10dp"
                android:layout_marginBottom="16dp"
                android:background="@drawable/round_shape"
                android:clickable="true"
                android:elevation="4dp"
                android:focusable="true"
                android:onClick="@{() -> viewModel.onCallBtnClicked()}"
                android:src="@drawable/ic_call_black" />


            <TextView
                android:id="@+id/chat_title_tv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="20dp"
                android:text="Mr. Samer Saadeh"
                android:textColor="@color/black"
                android:textSize="18sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/chat_car_tv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/chat_title_tv"
                android:layout_centerHorizontal="true"
                android:text="17 - White Hyundai"
                android:textColor="@color/text_gray"
                android:textSize="14sp"
                android:textStyle="bold" />


            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/chat_recyclerView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_above="@id/chat_layout"
                android:layout_below="@id/chat_car_tv"
                android:layout_marginTop="5dp"
                tools:itemCount="15"
                tools:listitem="@layout/item_chat" />

            <LinearLayout
                android:id="@+id/chat_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_marginTop="5dp"
                android:layout_marginBottom="45dp"
                android:orientation="horizontal"
                android:paddingStart="15dp"
                android:paddingEnd="15dp">

                <com.google.android.material.card.MaterialCardView
                    android:id="@+id/chat_cv"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="0.9"
                    android:elevation="5dp"
                    android:theme="@style/Theme.MaterialComponents.Light"
                    app:cardCornerRadius="30dp"
                    app:strokeColor="@color/gray_light"
                    app:strokeWidth="0.5dp">

                    <androidx.constraintlayout.widget.ConstraintLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@color/white"
                        android:padding="10dp">

                        <com.google.android.material.textfield.TextInputEditText
                            android:id="@+id/chat_et"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:background="@null"
                            android:ems="11"
                            android:hint="@string/type_a_message"
                            android:singleLine="true"
                            android:textColor="@color/text_black"
                            android:textColorHint="@color/hint_gray"
                            app:layout_constraintBottom_toBottomOf="parent"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toTopOf="parent"
                            app:layout_constraintWidth_percent="0.7" />

                        <ImageView
                            android:id="@+id/chat_attach_iv"
                            android:layout_width="20dp"
                            android:layout_height="20dp"
                            android:layout_marginEnd="10dp"
                            android:clickable="true"
                            android:focusable="true"
                            android:src="@drawable/ic_attach"
                            app:layout_constraintBottom_toBottomOf="parent"
                            app:layout_constraintEnd_toStartOf="@id/chat_camera_iv"
                            app:layout_constraintTop_toTopOf="parent" />

                        <ImageView
                            android:id="@+id/chat_camera_iv"
                            android:layout_width="20dp"
                            android:layout_height="20dp"
                            android:layout_marginEnd="15dp"
                            android:clickable="true"
                            android:focusable="true"
                            android:src="@drawable/ic_camera"
                            app:layout_constraintBottom_toBottomOf="parent"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintTop_toTopOf="parent" />

                    </androidx.constraintlayout.widget.ConstraintLayout>
                </com.google.android.material.card.MaterialCardView>

                <ImageView
                    android:id="@+id/chat_record_iv"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:clickable="true"
                    android:focusable="true"
                    android:src="@drawable/ic_mic_btn" />

            </LinearLayout>


        </RelativeLayout>
    </androidx.core.widget.NestedScrollView>
</RelativeLayout>

这是 activity 的 XML 文件,我在我的主题中将 windowFullscreen 设置为 false,我已经在清单中尝试了 adjustResize 和 adjustPan,我尝试通过代码设置它,我也尝试过有和没有 out RelativeLayout 键盘总是覆盖 recyclerView 和 editText 随时向我询问其他代码

Image showing the UI

你能试试这个吗?从 NestedScrollView 中移除包含 TextInputEditText 的线性布局,并将 windowSoftInputMode 设置为 adjustResize,如下所示:

在清单文件中:

 android:windowSoftInputMode="adjustResize"

布局文件是这样的:

<?xml version="1.0" encoding="utf-8"?>
<layout 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">

<data>

    <variable
        name="viewModel"
        type="app.redtaxi.client.views.chat.ChatViewModel" />
</data>
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:isScrollContainer="true"
        android:scrollbars="none">


        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/lesser_white"
            android:gravity="bottom"
            android:paddingTop="25dp"
            tools:context=".views.chat.ChatActivity">


            <RelativeLayout
                android:layout_width="42dp"
                android:layout_height="42dp"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                android:layout_marginStart="10dp"
                android:layout_marginTop="10dp"
                android:layout_marginBottom="16dp"
                android:background="@drawable/round_shape"
                android:clickable="true"
                android:elevation="4dp"
                android:focusable="true"
                android:onClick="@{() -> viewModel.onBackBtnClicked()}">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_centerInParent="true"
                    android:padding="10dp"
                    android:src="@drawable/ic_back_arrow" />

            </RelativeLayout>


            <ImageView
                android:layout_width="42dp"
                android:layout_height="42dp"
                android:layout_alignParentTop="true"
                android:layout_alignParentEnd="true"
                android:layout_marginTop="10dp"
                android:layout_marginEnd="10dp"
                android:layout_marginBottom="16dp"
                android:background="@drawable/round_shape"
                android:clickable="true"
                android:elevation="4dp"
                android:focusable="true"
                android:onClick="@{() -> viewModel.onCallBtnClicked()}"
                android:src="@drawable/ic_call_black" />


            <TextView
                android:id="@+id/chat_title_tv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="20dp"
                android:text="Mr. Samer Saadeh"
                android:textColor="@color/black"
                android:textSize="18sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/chat_car_tv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/chat_title_tv"
                android:layout_centerHorizontal="true"
                android:text="17 - White Hyundai"
                android:textColor="@color/text_gray"
                android:textSize="14sp"
                android:textStyle="bold" />


            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/chat_recyclerView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_above="@id/chat_layout"
                android:layout_below="@id/chat_car_tv"
                android:layout_marginTop="5dp"
                tools:itemCount="15"
                tools:listitem="@layout/item_chat" />

        </RelativeLayout>
    </androidx.core.widget.NestedScrollView>

 <LinearLayout
                android:id="@+id/chat_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_marginTop="5dp"
                android:layout_marginBottom="45dp"
                android:orientation="horizontal"
                android:paddingStart="15dp"
                android:paddingEnd="15dp">

                <com.google.android.material.card.MaterialCardView
                    android:id="@+id/chat_cv"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="0.9"
                    android:elevation="5dp"
                    android:theme="@style/Theme.MaterialComponents.Light"
                    app:cardCornerRadius="30dp"
                    app:strokeColor="@color/gray_light"
                    app:strokeWidth="0.5dp">

                    <androidx.constraintlayout.widget.ConstraintLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@color/white"
                        android:padding="10dp">

                        <com.google.android.material.textfield.TextInputEditText
                            android:id="@+id/chat_et"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:background="@null"
                            android:ems="11"
                            android:hint="@string/type_a_message"
                            android:singleLine="true"
                            android:textColor="@color/text_black"
                            android:textColorHint="@color/hint_gray"
                            app:layout_constraintBottom_toBottomOf="parent"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toTopOf="parent"
                            app:layout_constraintWidth_percent="0.7" />

                        <ImageView
                            android:id="@+id/chat_attach_iv"
                            android:layout_width="20dp"
                            android:layout_height="20dp"
                            android:layout_marginEnd="10dp"
                            android:clickable="true"
                            android:focusable="true"
                            android:src="@drawable/ic_attach"
                            app:layout_constraintBottom_toBottomOf="parent"
                            app:layout_constraintEnd_toStartOf="@id/chat_camera_iv"
                            app:layout_constraintTop_toTopOf="parent" />

                        <ImageView
                            android:id="@+id/chat_camera_iv"
                            android:layout_width="20dp"
                            android:layout_height="20dp"
                            android:layout_marginEnd="15dp"
                            android:clickable="true"
                            android:focusable="true"
                            android:src="@drawable/ic_camera"
                            app:layout_constraintBottom_toBottomOf="parent"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintTop_toTopOf="parent" />

                    </androidx.constraintlayout.widget.ConstraintLayout>
                </com.google.android.material.card.MaterialCardView>

                <ImageView
                    android:id="@+id/chat_record_iv"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:clickable="true"
                    android:focusable="true"
                    android:src="@drawable/ic_mic_btn" />

            </LinearLayout>
</RelativeLayout>