简体   繁体   English

键盘打开时调整布局大小

[英]Resize the layout when the keyboard opens

I want to resize my activity layout when the soft keyboard opens. 我想在打开软键盘时调整活动布局的大小。 I tried putting this in the manifest : 我试图把它放在清单中:

android:windowSoftInputMode="adjustResize"

but it doesn't work. 但这不起作用。 And this is my xml layout : 这是我的xml布局:

<RelativeLayout 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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".ui.SettingsActivity">

    <!-- BODY -->
    <ScrollView
        android:id="@+id/scrollViewBody"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <!-- my list -->

        </LinearLayout>
    </ScrollView>

    <!-- TOOLBAR -->
    <include layout="@layout/toolbar" />

Layout does not resize when keyboard opens... Help me please 键盘打开时布局不会调整大小...请帮助我

From the documentation 文档中

"adjustResize" The activity's main window is always resized to make room for the soft keyboard on screen. “ adjustResize”活动的主窗口总是调整大小,以便为屏幕上的软键盘腾出空间。

"adjustPan" The activity's main window is not resized to make room for the soft keyboard. “ adjustPan”活动的主窗口未调整大小以为软键盘腾出空间。 Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. 而是,窗口的内容会自动平移,以使当前焦点不会被键盘遮挡,并且用户始终可以看到他们正在键入的内容。 This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window. 通常,这不如调整大小那么可取,因为用户可能需要关闭软键盘才能到达窗口的模糊部分并与之交互。

I believe what you want is adjustPan . 我相信您想要的是adjustPan

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

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