键盘出现时布局正在挤压

时间:2015-01-17 14:54:20

标签: java android

当键盘弹出时,我的布局有点紧张。 这是我的xml文件

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true"
    android:focusable="true"
    android:focusableInTouchMode="true">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="10"
        android:background="@android:color/white">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:weightSum=".9"
            android:layout_weight="2"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="1dp"
                android:layout_weight=".01" />
            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_weight=".3"
                android:paddingLeft="12dp"
                android:id="@+id/username"
                android:hint="@string/username"
                android:textColorHint="@color/edittextcolor"/>

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:layout_marginLeft="10dp"
                android:hint="@string/password"
                android:layout_weight=".3"
                android:paddingLeft="12dp"
                android:textColorHint="@color/edittextcolor"
                android:layout_marginRight="10dp"
                android:id="@+id/password" />

         </LinearLayout>

         <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight=".7"
                android:weightSum="2"
                android:layout_marginTop="30dp">

            <Button
                android:id="@+id/signup"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="@string/Sign"
                android:textColor="@android:color/white"
                android:layout_marginLeft="20dp" />

            <Button
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="@string/login"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:textColor="@android:color/white" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="4" >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="3"/>
        </LinearLayout>
    </LinearLayout>
</ScrollView>

当键盘没有出现时,布局看起来很好。我已经添加了 android:windowSoftInputMode =“adjustResize”在mainifest文件中。但它仍然无法正常工作。  任何帮助将不胜感激。谢谢提前..

1 个答案:

答案 0 :(得分:0)

更改

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical" 
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:weightSum="10"
 android:background="@android:color/white">

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

希望你的问题能够得到解决。