android软键盘出现时会破坏布局

Nic*_*ick 10 android android-layout android-softkeyboard

这是一个布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="0px"
            android:layout_weight="1" />

        <FrameLayout
            android:background="#0000ff"
            android:layout_width="match_parent"
            android:layout_height="0px"
            android:layout_weight="1" />

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="0px"
            android:layout_weight="1" />

    </LinearLayout>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

当触摸EditText并出现软键盘时,我希望蓝条保持不变.即我希望保留它的大小和位置.我android:windowSoftInputMode在AndroidManifest中尝试了我的activity参数的所有四个可能值.并且总是我的蓝色条在软键盘上移动或缩小:

android:windowSoftInputMode="adjustUnspecified" 或默认情况下:

在此输入图像描述

android:windowSoftInputMode="adjustPan"或者android:windowSoftInputMode="adjustNothing":

在此输入图像描述

android:windowSoftInputMode="adjustResize":

在此输入图像描述

当软键盘出现时,它是否可以保持相同的大小和位置?

سعی*_* .م 6

您必须用作<ScrollView>主要布局。例子:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent">
   ....
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

或者在 AndroidManiFest.xml 中使用以下代码:

<activity
     android:windowSoftInputMode="adjustNothing">
</activity>
Run Code Online (Sandbox Code Playgroud)


Ric*_*lor 1

由于输入是进入EditText你的,所以它总是会移动一些东西。

考虑采用两种布局,一种用于键盘按下时,一种用于键盘弹起时。

使用 aViewSwitcher可能会有所帮助。