Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid changes in Android's UI, when keyboard is up or orientation is changed?

I have a rather simple login page in my Android app, containing a header, username TextView, password TextView, Login button and an 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 I think are related:

  1. When the keyboard is up, and I scroll down, I see that the image footer "hides" behind the login button, instead of staying below it.
  2. The same is happening when the screen is oriented horizontally.

The things I've tried:

  1. Setting in the activity android:windowSoftInputMode="adjustPan", but I want to be able to scroll down when the keyboard appears, or android:windowSoftInputMode="adjustResize", or any other param for that matter.
  2. Setting marginBottom in the button.

Neither worked. I would appreciate any help.

like image 368
MichalK Avatar asked Nov 03 '22 19:11

MichalK


1 Answers

Open your manifest.xml file .change in your activity tab .

<activity
            android:configChanges="keyboardHidden|orientation" 
            android:name=".testActivity"
            android:label="@string/app_name"></activity>
like image 83
Dhruvil Patel Avatar answered Nov 09 '22 10:11

Dhruvil Patel