简体   繁体   English

出现软键盘时使用 Recycler View 调整布局大小

[英]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.我有一个布局,其中包含 Recycler View、工具栏和布局底部的 EditText。我想在出现软键盘时调整回收器视图的大小。工具栏应保留在顶部,edittext 应随键盘向上移动。只应调整回收器视图的大小。

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.我在全屏模式下使用window。目前的情况是,当软键盘出现时,整个布局被向上推,工具栏不可见,只有一部分回收站视图可见。

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.我有一个布局,其中包含布局底部的回收器视图、工具栏和 EditText。我想在软键盘出现时调整回收器视图的大小。工具栏应保持在顶部,编辑文本应随键盘向上移动。只有回收站视图应该调整大小。

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.我在全屏模式下使用window。目前的情况是当软键盘出现时整个布局向上推,工具栏不可见,只有一部分回收器视图可见。

Thank you!谢谢!

add android:windowSoftInputMode="adjustResize" to the activity tag on the manifest.xmlandroid:windowSoftInputMode="adjustResize"添加到清单上的活动标签。xml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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