【问题标题】:Make bottom layout stay on bottom when keyboard is displayed while other layouts move up当其他布局向上移动时显示键盘时使底部布局保持在底部
【发布时间】:2018-09-27 03:32:56
【问题描述】:

在您下方将显示说明开始布局的屏幕截图、我不满意的当前结果以及我想要的结果:

这是完美的开场布局:

然后是我在显示我不满意的键盘时得到的当前布局:

那么我想要的结果:

那一行代码是否会让底部布局忽略android:windowSoftInputMode="stateVisible|adjustResize"?或者我该怎么做?

更新:

这就是我通过adjustPan 得到的:

【问题讨论】:

  • 你试过android:windowSoftInputMode="adjustPan"吗?

标签: java android android-layout android-studio keyboard


【解决方案1】:

因为你正在使用

adjustResize,

所以窗口正在调整大小以便为键盘腾出空间 你应该使用

android:windowSoftInputMode="adjustPan"

使用此窗口将不会调整大小,并且当前焦点永远不会被键盘遮挡,用户始终可以看到他们正在输入的内容。

【讨论】:

    【解决方案2】:

    设置 android:layout_alignParentBottom="true" 在您的布局中,例如我的布局中的 ScrollView

    在清单中添加

    android:windowSoftInputMode="adjustResize"

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/main_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white"
        android:gravity="top"
        android:orientation="horizontal"
        android:visibility="visible"
        android:weightSum="1">
    
    
    
        <ScrollView
            android:id="@+id/scrollView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/btn_search"
            android:padding="10dp"
            android:scrollbars="none">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
    
    
            </LinearLayout>
        </ScrollView>
    
        <Button
            android:id="@+id/btn_search"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_gravity="center"
            android:layout_marginBottom="10dp"
            android:padding="15dp"
            android:text="@string/test_search"
            android:textAllCaps="false"
            android:textAppearance="?android:attr/textAppearanceMedium" />
    </RelativeLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多