简体   繁体   中英

Resizing of Layout with Recycler View when the soft keyboard appears

I have a layout which contains Recycler View,toolbar and an EditText at the bottom of the Layout.I want to resize the recycler view when the soft keyboard appears.The toolbar should remain on the top and the edittext should move up with the keyboard.Only the recycler view should be resized.

The layout code is as follows

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="vertical"
    android:background="#ffffff">
    <androidx.appcompat.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="#fff"
        android:elevation="4dp"
        app:title="Toolbar" />

    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ffffff"
        android:gravity="center"
        android:orientation="horizontal"
        android:padding="8dp">
        <EditText
            android:layout_width="0dp"
            android:layout_height="45dp"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:backgroundTint="#757575"
            android:textCursorDrawable="@drawable/cursor_color"
            android:textSize="16sp" />
    </LinearLayout>
</LinearLayout>

I am using the window in full screen mode.The Current situation is that the entire layout is pushed upwards when the soft keyboard appears,toolbar is invisible and only a part of the recycler view is visible.

Thank you!

I have a layout which contains Recycler View,toolbar and an EditText at the bottom of the Layout.I want to resize the recycler view when the soft keyboard appears.The toolbar should remain on the top and the edittext should move up with the keyboard.Only the recycler view should be resized.

The layout code is as follows

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="vertical"
    android:background="#ffffff">
    <androidx.appcompat.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="#fff"
        android:elevation="4dp"
        app:title="Toolbar" />

    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ffffff"
        android:gravity="center"
        android:orientation="horizontal"
        android:padding="8dp">
        <EditText
            android:layout_width="0dp"
            android:layout_height="45dp"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:backgroundTint="#757575"
            android:textCursorDrawable="@drawable/cursor_color"
            android:textSize="16sp" />
    </LinearLayout>
</LinearLayout>

I am using the window in full screen mode.The Current situation is that the entire layout is pushed upwards when the soft keyboard appears,toolbar is invisible and only a part of the recycler view is visible.

Thank you!

add android:windowSoftInputMode="adjustResize" to the activity tag on the manifest.xml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM