简体   繁体   中英

Layout is squeezing when keyboard appears

My layout is squeezing a little when keyboard pops up. Here is my xml file

<?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>

The layout is looking good when the keyboard is not appearing.I have added android:windowSoftInputMode="adjustResize" in the mainifest file.But still it isn't working. Any help will be much appreciated.Thanks in advance..

Change

 <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">

to

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

Hope your problem will be solved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM