软键盘改变了我的布局大小

时间:2014-09-18 15:44:47

标签: android android-layout android-edittext

在编辑文本单击后出现软键盘时,我遇到布局问题(edittext和内部按钮)。整个布局重新设置(变小),内部元素(edittext)变小。情况看起来像这样,我有2个布局,其中第一个占据50%的屏幕,而下面是更安全的布局。在第二个布局中,我有所有的editext和按钮,我想要保持原始大小的布局 - 只需在键盘出现时将布局放得更高。我尝试ajdustPan,adjustResize和其他,并不知道如何解决它。

我在该布局中使用%来指定元素高度,我也将ScrollView作为第一个布局,但这也无效。我的布局层次结构:

  • 滚动型
    • RelativeLayout的
      • RelativeLayout(50% - 空间大小)(alignBottom space)
      • 空间
      • LinearLayout(50% - 空间大小)(layout_below space)

在LinearLayout中我有2个Edittext。

有人有建议吗?感谢

1 个答案:

答案 0 :(得分:1)

在清单文件中设置android:windowSoftInputMode =" stateUnchanged | adjustPan"在Activity标签中。希望这能解决你的问题。

我试过.xml文件:

<ScrollView 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:id="@+id/top"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <ImageView
            android:id="@+id/container"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:layout_marginTop="50dp"
            android:src="@drawable/ic_launcher" />

        <Button
            android:id="@+id/button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/container"
            android:layout_marginTop="50dp"
            android:clickable="true"
            android:onClick="removeFragment"
            android:text="Remove" />

        <Button
            android:id="@+id/button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/container"
            android:layout_marginTop="50dp"
            android:clickable="true"
            android:onClick="removeFragment"
            android:text="Remove" />
    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/top"
        android:orientation="vertical" >

        <Button
            android:id="@+id/button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="50dp"
            android:clickable="true"
            android:onClick="removeFragment"
            android:text="Remove" />

        <EditText
            android:id="@+id/userName"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="50dp"
            android:hint="Username"
            android:imeOptions="actionDone"
            android:inputType="text"
            android:maxLines="1"
            android:singleLine="true" />
    </LinearLayout>
</RelativeLayout>

清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.test.MainActivity"
        android:windowSoftInputMode="stateUnchanged|adjustPan"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

相关问题