Zach
Zach

Reputation: 1321

How to allow of contents behind the soft keyboard in android?

I have a scrollview that has android:fillViewport="true" so that it fills the screen when there is no keyboard. I want to add functionality so that the scrollview doesn't change when a keyboard pops up, but rather allows you to scroll the contents up from BEHIND the keyboard.
Is this possible? I don't want the keyboard to pop up and everything gets squished together. Does anyone have a solution to this?

Upvotes: 1

Views: 204

Answers (1)

Jitender Dev
Jitender Dev

Reputation: 6925

Setting height and width of scroll view to "match_parent" is the trick here.

Check below layout, it will help you.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_parent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ScrollView
        android:id="@+id/scroll_parent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="38dp" >

        <LinearLayout
            android:id="@+id/relative_parent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingLeft="13dp"
            android:paddingRight="8dp" >

            <EditText
                android:id="@+id/et_fullname"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:digits="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                android:imeOptions="actionNext"
                android:inputType="textPersonName"
                android:maxLength="30"
                android:maxWidth="208dp"
                android:paddingLeft="5dp"
                android:singleLine="true"
                android:textSize="13sp" />

            <EditText
                android:id="@+id/et_email"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="200dp"
                android:imeOptions="actionNext"
                android:inputType="textEmailAddress"
                android:maxLength="30"
                android:maxWidth="208dp"
                android:paddingLeft="5dp"
                android:textSize="13sp" />

            <EditText
                android:id="@+id/et_phone"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="400dp"
                android:digits="1234567890"
                android:imeOptions="actionNext"
                android:inputType="phone"
                android:maxLength="12"
                android:paddingLeft="5dp"
                android:singleLine="true"
                android:textSize="13sp" />

            <EditText
                android:id="@+id/et_fax"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:digits="1234567890"
                android:imeOptions="actionDone"
                android:inputType="phone"
                android:maxLength="12"
                android:paddingLeft="5dp"
                android:singleLine="true"
                android:textSize="13sp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="200dp"
                android:text="Botttom Text" />
        </LinearLayout>
    </ScrollView>

</LinearLayout>

Upvotes: 1

Related Questions