How to avoid changes in the Android user interface when changing the keyboard or orientation?

I have a pretty simple login page for an Android app containing the title, TextView username, TextView password, login button and image footer:

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

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#ffffff" >

    <!-- Header  Starts -->

    <LinearLayout
        android:id="@+id/header"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        >

        <!-- Logo Start -->

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dip"
            android:src="@drawable/header" />
        <!-- Logo Ends -->
    </LinearLayout>

    <!-- Header Ends -->

    <!-- Footer Start -->
    <LinearLayout android:id="@+id/footer"
    android:layout_width="fill_parent"
    android:layout_height="90dip"
    android:layout_alignParentBottom="true"
    android:gravity="center">
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dip"
            android:src="@drawable/footer" />
    </LinearLayout>
    <!-- Footer Ends -->

    <!-- Login Form -->

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="10dip"
        android:layout_below="@+id/header"
         >

        <!-- Application Name Label -->
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/app_name"
            android:gravity="center"
            android:padding="10dip"
            android:textSize="25dp"
            android:textStyle="bold"
        />

        <!-- Username Label -->

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="User Name"
            android:textColor="#372c24" />

        <EditText
            android:id="@+id/username"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dip"
            android:layout_marginTop="5dip"
            android:singleLine="true" />
        <!-- Password Label -->

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Password"
            android:textColor="#372c24" />

        <EditText
            android:id="@+id/password"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dip"
            android:layout_marginTop="5dip"
            android:password="true"
            android:singleLine="true" />
        <!-- Login button -->

        <Button
            android:id="@+id/btnLogin"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dip"
            android:text="Logon" />
        </LinearLayout>
        <!-- Login Form Ends -->

    </RelativeLayout>
 </ScrollView>

I have two problems that I think of:

  • When the keyboard is inserted and I scroll down, I see that the image footer is “hiding” behind the login button, instead of staying below it.
  • The same thing happens when the screen is oriented horizontally.

What I tried:

  • The activity setting android:windowSoftInputMode="adjustPan", but I want to scroll down when the keyboard appears, or android:windowSoftInputMode="adjustResize"or any other parameter, if it is important.
  • Setting marginBottomin the button.

. .

+5
3

RelativeLayout: id LinearLayout " " "form" ImageView, : android: layout_below = "@+ id/form". . :

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#ffffff" >

    <!-- Header  Starts -->
    <LinearLayout
        android:id="@+id/header"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center">

        <!-- Logo Start -->
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dip"
            android:src="@drawable/header" />
        <!-- Logo Ends -->

    </LinearLayout>
    <!-- Header Ends -->

    <!-- Login Form -->
    <LinearLayout
        android:id="@+id/form"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="10dip"
        android:layout_below="@+id/header">

        <!-- Application Name Label -->
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/app_name"
            android:gravity="center"
            android:padding="10dip"
            android:textSize="25dp"
            android:textStyle="bold"/>

        <!-- Username Label -->
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="User Name"
            android:textColor="#372c24" />

        <EditText
            android:id="@+id/username"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dip"
            android:layout_marginTop="5dip"
            android:singleLine="true" />

        <!-- Password Label -->
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Password"
            android:textColor="#372c24" />

        <EditText
            android:id="@+id/password"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dip"
            android:layout_marginTop="5dip"
            android:password="true"
            android:singleLine="true" />

        <!-- Login button -->
        <Button
            android:id="@+id/btnLogin"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dip"
            android:text="Logon" />
    </LinearLayout>
    <!-- Login Form Ends -->

    <!-- Footer Start -->
    <LinearLayout android:id="@+id/footer"
        android:layout_width="fill_parent"
        android:layout_height="90dip"
        android:layout_alignParentBottom="true"
        android:gravity="bottom|center"
        android:paddingBottom="10dip"
        android:layout_below="@+id/form"

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dip"
            android:src="@drawable/footer" />

        </LinearLayout>
        <!-- Footer Ends -->

    </RelativeLayout>

</ScrollView>

.

+1

manifest.xml.change .

<activity
            android:configChanges="keyboardHidden|orientation" 
            android:name=".testActivity"
            android:label="@string/app_name"></activity>
+1
<activity
            android:configChanges="adjustPan" 
            android:name=".testActivity"
            android:label="@string/app_name"></activity>

See "Android: windowSoftInputMode". Available modes here

0
source

All Articles