Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android making layout scrollable when soft keyboard open, but not shifting it upwards

This is my screen, with one button hidden behind the keyboard.

I want exactly like this, but scrollable. -

keyboard open with one button hidden behind

Whenever, the keyboard gets opened, I want to make look it the same as in image. But, instead to make it scrollable, so that the user can scroll to view the bottom part of the screen (including button), even when the keyboard is open.

I tried -

android:windowSoftInputMode="adjustResize"

but, this shifts the bottom part upwards, whenever keyboard is opened.

as in this image -

I don't want this - (shifting of Create Account button upwards, when keypad is opened)

enter image description here

CREATE ACCOUNT button must be visible after scrolling.

Here is the layout -

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:id="@+id/root_layout"
    android:fillViewport="true"

    >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"

        android:weightSum="10"

        >
        <LinearLayout  android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="9"
            android:orientation="vertical"
            android:gravity="center_vertical|center_horizontal"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin"
            android:paddingBottom="@dimen/activity_vertical_margin">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:orientation="vertical">


                <EditText
                    android:id="@+id/et_username_or_email"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/et_hint_username_or_email"
                    android:inputType="textEmailAddress"
                    android:singleLine="true"
                    />
                <EditText
                    android:id="@+id/et_pswd"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/et_hint_password"
                    android:password="true"
                    android:singleLine="true"
                    />

                <Button
                    android:id="@+id/btn_sign_in"
                    android:layout_marginTop="10dp"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/btn_sign_in"
                    android:background="@color/lighter_orange"
                    android:textColor="@android:color/white"/>

                <TextView
                    android:layout_marginTop="10dp"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/or"
                    android:gravity="center_horizontal"
                    android:textColor="@android:color/black"/>


                <Button
                    android:id="@+id/btn_take_a_peek"
                    android:layout_marginTop="10dp"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/btn_take_a_peek"
                    android:textColor="@android:color/white"
                    android:background="@color/button_gray"/>

                <TextView
                    android:layout_marginTop="15dp"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/forgot_password"
                    android:gravity="center_horizontal"
                    android:textColor="@color/text_gray"/>
            </LinearLayout>
        </LinearLayout>
        <LinearLayout  android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="vertical">


            <Button
                android:id="@+id/btn_create_account"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="@string/btn_create_account"
                android:background="@color/button_very_light_orange"
                android:textColor="@android:color/white"/>


        </LinearLayout>
    </LinearLayout>
</ScrollView>

Please help me to fix this up.

like image 611
Narendra Singh Avatar asked Aug 19 '15 12:08

Narendra Singh


People also ask

How can I make my layout scroll vertically in Android?

Vertical Scroll view provide by android. widget. ScrollView class. It is used to scroll child views in a vertical direction.

How do you move the layout up when the soft keyboard is shown Android activity?

Sometimes, you need to change the layout when the soft keyboard appeared on the screen. You can fix this by adding a line of code into the AndroidManifest. xml file within the relevant activity section. Add this code to the activity.


2 Answers

Add this input mode in your manifest file.

android:windowSoftInputMode="stateHidden|adjustResize"
like image 79
Lalit Sharma Avatar answered Oct 21 '22 14:10

Lalit Sharma


I had the same Problem and solved it.

Add this to your class inside the <activity> tags in the AndroidManifest in your Class:

android:windowSoftInputMode="stateHidden|adjustResize">

or:

<activity
        android:name="com.app.app.RegisterScreen"
        android:parentActivityName="com.app.app.LogInScreen"
        android:windowSoftInputMode="stateHidden|adjustPan">

    </activity>

Example:

<activity
        android:name="com.app.yourapp.LogInScreen"
        android:windowSoftInputMode="stateHidden|adjustPan">

</activity>

This works for me.

like image 40
korunos Avatar answered Oct 21 '22 12:10

korunos