Android弹出软键盘时底部菜单与ScrollView冲突的问题

如图所示,应用底部有个菜单,上面是个ScrollView,弹出键盘是我希望菜单跟随着键盘移动到上面,但是此时会遮挡输入光标。比如,我点了test12,焦点处于test12上,但是正好被菜单给挡住了,有什么好的办法解决这个问题吗?

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
       <LinearLayout
           android:orientation="vertical"
           android:layout_gravity="center_vertical"
           android:layout_width="match_parent"
           android:layout_height="wrap_content">
           <EditText
               android:hint="test1"
               android:layout_width="match_parent"
               android:layout_height="50dp" />
           <EditText
               android:hint="test2"
               android:layout_width="match_parent"
               android:layout_height="50dp" />
           <EditText
               android:hint="test3"
               android:layout_width="match_parent"
               android:layout_height="50dp" />
           <EditText
               android:hint="test4"
               android:layout_width="match_parent"
               android:layout_height="50dp" />
           <EditText
               android:hint="test5"
               android:layout_width="match_parent"
               android:layout_height="50dp" />
           <EditText
               android:hint="test6"
               android:layout_width="match_parent"
               android:layout_height="50dp" />
           <EditText
               android:hint="test7"
               android:layout_width="match_parent"
               android:layout_height="50dp" />
           <EditText
               android:hint="test8"
               android:layout_width="match_parent"
               android:layout_height="50dp" />
           <EditText
               android:hint="test9"
               android:layout_width="match_parent"
               android:layout_height="50dp" />
           <EditText
               android:hint="test10"
               android:layout_width="match_parent"
               android:layout_height="50dp" />
           <EditText
               android:hint="test11"
               android:layout_width="match_parent"
               android:layout_height="50dp" />
           <EditText
               android:hint="test12"
               android:layout_width="match_parent"
               android:layout_height="50dp" />
           <EditText
               android:hint="test13"
               android:layout_width="match_parent"
               android:layout_height="50dp" />
           <EditText
               android:hint="test14"
               android:layout_width="match_parent"
               android:layout_height="50dp" />
       </LinearLayout>
    </ScrollView>
    <LinearLayout
        android:layout_alignParentBottom="true"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:gravity="center_horizontal"
            android:background="#FFAA00"
            android:text="我的菜单"
            android:textSize="40sp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>
</RelativeLayout>

图片描述图片描述

阅读 9k
3 个回答
 android:windowSoftInputMode=["stateUnspecified",
                                       "stateUnchanged", "stateHidden",
                                       "stateAlwaysHidden", "stateVisible",
                                       "stateAlwaysVisible", "adjustUnspecified",
                                       "adjustResize", "adjustPan"]

键盘的弹出有这么几种模式,可以组合着使用 ,你试试adjustResize和adjustPan,以及组合使用stateVisible试试。

新手上路,请多包涵

比较简单的说法,就是设置scrollview的contentInset.bottom为键盘高度。这样应该可以的吧。。

新手上路,请多包涵

adjustResize模式,你试试。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题