Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Soft keyboard doesnt trigger scrolling in a ScrollView

I know there are many many questions here on SO regarding the problem with EditText, showing the soft input keyboard and what you should have in the manifest (adjustPan or adjustResize).

I have read a lot of the questions and answers here, but have not been able to solve my problem.

Its actually quite simple: I have a login Activity and all content fits on one screen when the keyboard is NOT shown. At the bottom of this Login Activity, I have a button that should always be at the bottom. When focusing on one EditText, the keyboard shows up and hides some stuff. When the keyboard is up, I would like to be able to scroll down, but I cannot.

  • I have set the activity to "adjustPan" in the manifest

Here are two images, without and with the keyboard:

enter image description hereenter image description here

Now, when the keyboard is up, I would like to scroll down to see the buttons (the yellow and on the bottom). I cannot do it.

If I instead set, in the manifest, to "adjustRezise", I get another unwanted effect as can be seen here:

enter image description here

The button at the bottom is no "on top of" the other things, but I cannot scroll (so that the "logga in" button can be viewed).

The first question is: why isnt the scrolling functioning with "adjustPan" and when the keyboard is hiding stuff? That is the reasonable thing I'd say.

Here is my XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout6"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/taxibg3"
    android:orientation="vertical" >

    <ScrollView
        android:id="@+id/ScrollView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/login_logoBarInclude"
        android:fillViewport="true"
        android:orientation="vertical" >

        <RelativeLayout
            android:id="@+id/login_form"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <LinearLayout
                android:id="@+id/iv1"
                android:layout_width="240dp"
                android:layout_height="280dp"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="5dp"
                android:background="@drawable/login_square_adapted"
                android:orientation="vertical"
                android:paddingTop="15dp" >

                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:text="@string/vehicleLogin"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="#ffffff" />

                <FrameLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="3dp"
                    android:layout_marginRight="3dp"
                    android:layout_marginTop="10dp" >

                    <include layout="@layout/menu_divider_horizontal" >
                    </include>
                </FrameLayout>

                <RelativeLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="30dp"
                    android:layout_marginRight="30dp"
                    android:layout_marginTop="35dp"
                    android:gravity="center_horizontal"
                    android:orientation="vertical" >

                    <EditText
                        android:id="@+id/login_carNumber"
                        style="@style/EditTextDark"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_toRightOf="@+id/login_car_icon"
                        android:hint="@string/prompt_carNumber"
                        android:inputType="phone"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textCursorDrawable="@null" >

                        <requestFocus />
                    </EditText>

                    <ImageView
                        android:id="@+id/login_car_icon"
                        android:layout_width="40dp"
                        android:layout_height="40dp"
                        android:src="@drawable/user" />

                    <EditText
                        android:id="@+id/login_password"
                        style="@style/EditTextDark"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@id/login_carNumber"
                        android:layout_marginTop="10dp"
                        android:layout_toRightOf="@+id/login_lock_icon"
                        android:hint="@string/prompt_password"
                        android:inputType="phone"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textCursorDrawable="@null" >
                    </EditText>

                    <ImageView
                        android:id="@+id/login_lock_icon"
                        android:layout_width="40dp"
                        android:layout_height="40dp"
                        android:layout_alignTop="@id/login_password"
                        android:layout_below="@id/login_car_icon"
                        android:src="@drawable/lock" />

                    <Button
                        android:id="@+id/sign_in_button"
                        android:layout_width="fill_parent"
                        android:layout_height="40dp"
                        android:layout_alignParentBottom="true"
                        android:layout_centerHorizontal="true"
                        android:layout_marginBottom="10dp"
                        android:background="@drawable/button_rounded"
                        android:gravity="center_horizontal"
                        android:paddingTop="5dp"
                        android:text="@string/action_sign_in_short"
                        android:textColor="#000000" />
                </RelativeLayout>
            </LinearLayout>
        </RelativeLayout>
    </ScrollView>


    <Button
        android:id="@+id/quit_app_button"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="@string/action_exit_app" />

</RelativeLayout>

======= EDIT =========

So, I changed the layout according to Josephs suggestion, but now the "height is very large", even though there is no reason for it, ie the button at the end is "far down", so you need to scroll "far down" to see it, instead of being at the bottom of the screen. I hope you understand what I mean:

Notice the scrollbar on the right, and the button isnt seen, as it is "far down"

*Notice the scrollbar on the right, and the button isnt seen, as it is "far down". Also, the background is stretched, so that would mean that the RelativeLayout called "linearLayoyt6" (confusing, yes) is expanding down for some reason... *

I have tried setting the height to a fixed dp, for the ScrollView, and the layouts below but nothing has helped. And the XML is like this:

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

    <RelativeLayout
        android:id="@+id/linearLayout6"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/taxibg3"
        android:orientation="vertical" >

        <RelativeLayout
            android:id="@+id/login_form"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            >

            <LinearLayout
                android:id="@+id/iv1"
                android:layout_width="240dp"
                android:layout_height="280dp"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="25dp"
                android:background="@drawable/login_square_adapted"
                android:orientation="vertical"
                android:paddingBottom="0dp"
                android:paddingLeft="0dp"
                android:paddingRight="0dp"
                android:paddingTop="15dp" >

                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:text="@string/vehicleLogin"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="#ffffff" />

                <FrameLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="3dp"
                    android:layout_marginRight="3dp"
                    android:layout_marginTop="10dp" >

                    <include layout="@layout/menu_divider_horizontal" >
                    </include>
                </FrameLayout>

                <RelativeLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="30dp"
                    android:layout_marginRight="30dp"
                    android:layout_marginTop="35dp"
                    android:gravity="center_horizontal"
                    android:orientation="vertical" >

                    <EditText
                        android:id="@+id/login_carNumber"
                        style="@style/EditTextDark"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_toRightOf="@+id/login_car_icon"
                        android:hint="@string/prompt_carNumber"
                        android:inputType="phone"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textCursorDrawable="@null" >

                        <requestFocus />
                    </EditText>

                    <ImageView
                        android:id="@+id/login_car_icon"
                        android:layout_width="40dp"
                        android:layout_height="40dp"
                        android:src="@drawable/user" />

                    <EditText
                        android:id="@+id/login_password"
                        style="@style/EditTextDark"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@id/login_carNumber"
                        android:layout_marginTop="10dp"
                        android:layout_toRightOf="@+id/login_lock_icon"
                        android:hint="@string/prompt_password"
                        android:inputType="phone"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textCursorDrawable="@null" >
                    </EditText>

                    <ImageView
                        android:id="@+id/login_lock_icon"
                        android:layout_width="40dp"
                        android:layout_height="40dp"
                        android:layout_alignTop="@id/login_password"
                        android:layout_below="@id/login_car_icon"
                        android:src="@drawable/lock" />
                </RelativeLayout>

                <FrameLayout
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_marginTop="30dp"
                    android:background="@drawable/login_square_half"
                    android:padding="0dp" >

                    <Button
                        android:id="@+id/sign_in_button"
                        android:layout_width="120dp"
                        android:layout_height="40dp"
                        android:layout_gravity="center_vertical|center_horizontal"
                        android:background="@drawable/button_rounded"
                        android:gravity="center_horizontal"
                        android:text="@string/action_sign_in_short"
                        android:textColor="#000000" />
                </FrameLayout>
            </LinearLayout>
        </RelativeLayout>

        <Button
            android:id="@+id/quit_app_button"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:text="@string/action_exit_app" />
    </RelativeLayout>

</ScrollView>
like image 260
Ted Avatar asked Jan 13 '13 14:01

Ted


1 Answers

Try changing the resizeMode to adjustResize and moving the ScrollView from inside your RelativeLayout linearLayout6 to outside and setting the layout_height of the RelativeLayout to wrap_content.

like image 58
Joseph Earl Avatar answered Sep 22 '22 07:09

Joseph Earl