Android Keyboard covers edittext under recyclerView

Viewed 401
<?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>

this is the XML file for the activity i have windowFullscreen set to false in my theme and i have tried adjustResize and adjustPan in the manifest and i tried setting it by code i also tried with and without the out RelativeLayout the Keyboard always covers the recyclerView and the editText feel free to ask me for other prats of the code

Image showing the UI

1 Answers

Can you try this? Remove the Linear Layout containing the TextInputEditText out of the NestedScrollView and set windowSoftInputMode to adjustResize like this:

In the manifest file:

 android:windowSoftInputMode="adjustResize"

and the layout file like this:

<?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>
Related