Ad

Getting The Background Image To Not "squash" When One Of The Text Input's Is Clicked To Bring Up The Keyboard

- 1 answer

So I'm a beginner to coding android and normally I'm able to find my solutions on google but I've had no luck this time. I've made an app with two activities (a login screen that also has a register button that leads to a register screen) and on the initial log in screen, clicking one of the text inputs squashes the background image, to essentially fit it into the smaller space created when the keyboard takes up some of the screen. It's pretty annoying.

Sorry for pasting such a huge block of code but as a beginner, I'm not really sure which part of this code is relevant so I've included the whole xml. Thanks!

Oh, and again - I can't stress enough that I'm a total noob - so could any answers please state crystal clear exactly what code I should be changing/including and in what file, and where abouts in that file?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:gravity="center_horizontal"
    android:orientation="vertical"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:background="@drawable/qlogoonwallpaper"
    tools:context=".MainActivity">

    <!-- Login progress -->
    <ProgressBar
        android:id="@+id/login_progress"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:visibility="gone" />

    <ScrollView
        android:id="@+id/login_form"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="32dp"
        android:layout_marginBottom="48dp">

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

            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <AutoCompleteTextView
                    android:id="@+id/email"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:dropDownWidth="match_parent"
                    android:hint="@string/prompt_email"
                    android:inputType="textEmailAddress"
                    android:maxLines="1"
                    android:singleLine="true" />

            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <EditText
                    android:id="@+id/password"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/prompt_password"
                    android:imeActionId="6"
                    android:imeActionLabel="@string/action_sign_in_short"
                    android:imeOptions="actionUnspecified"
                    android:inputType="textPassword"
                    android:maxLines="1"
                    android:singleLine="true" />

            </android.support.design.widget.TextInputLayout>

            <Button
                android:id="@+id/email_sign_in_button"
                style="?android:textAppearanceSmall"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="16dp"
                android:background="@color/colorPrimaryDark"
                android:text="@string/action_sign_in"
                android:textAllCaps="false"
                android:textColor="@android:color/background_light"
                android:textStyle="bold" />
        </LinearLayout>
    </ScrollView>

    <EditText
        android:id="@+id/editText3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="-208dp"
        android:ems="10"
        android:hint="@string/prompt_email"
        android:inputType="textEmailAddress" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="225dp"
        android:background="@android:color/transparent"
        android:text="@string/register_intro"
        android:textAllCaps="false"
        android:textColor="@android:color/background_light"
        android:textSize="18sp"
        android:textStyle="bold|italic" />

</RelativeLayout>
Ad

Answer

Inside the Android Manifest file, try adding the following attribute for your MainActivity :

<activity
            android:name=".MainActivity"
            android:windowSoftInputMode="adjustPan">
...
</activity>

that makes the views pan when the soft keyboard appears but the activity's window is not resized. See if that makes any difference. If resizing would work better, instead of the "adjustPan" attribute, you can add "adjustResize". Hopefully one of the two will do the trick for you.

Ad
source: stackoverflow.com
Ad