Android ScrollView refuses to scroll to bottom

Doge picture Doge · Jul 26, 2012 · Viewed 12k times · Source

I have a root scrollview element with a relativelayout in it, and a bunch of form elements inside the relative layout.

For some reason, when the soft keyboard is up it seems unable to scroll all the way to the bottom, which cuts one of my buttons in half.

Here is a screenshot of the hierarchy viewer to demonstrate what I mean.

enter image description here

As you can see, the system knows that the view continues past the keyboard, yet the scrollview (which fills the visible part of the screen correctly) won't continue to scroll down as it should.

I have android:windowSoftInputMode="adjustResize" in the manifest for the activity, and I can/will not switch it to pan.

Any help is appreciated.

edit: I am seeing this in more than 1 view. Here is the xml of another view with the same problem:

<?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="wrap_content"
    android:background="@drawable/background" >
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="32dp" >
        <EditText
            android:id="@+id/reset_oldpass"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:ems="10"
            android:singleLine="true"
            android:hint="@string/current_password"
            android:layout_marginTop="16dp" />
        <EditText
            android:id="@+id/reset_pass1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/reset_oldpass"
            android:ems="10"
            android:hint="@string/reset_new_pass"
            android:inputType="textPassword"
            android:layout_marginTop="16dp" />
        <EditText
            android:id="@+id/reset_pass2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/reset_pass1"
            android:ems="10"
            android:hint="@string/reset_confirm_pass"
            android:inputType="textPassword"
            android:layout_marginTop="16dp" />
        <TextView
            android:id="@+id/reset_forgot_password"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/reset_pass2"
            android:layout_marginTop="16dp"
            android:textColor="@color/Link"
            android:textStyle="bold"
            android:text="@string/Login_forgot_password" />
        <Button
            android:id="@+id/reset_reset_password_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/reset_forgot_password"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="16dp"
            android:layout_marginBottom="32dp"
            android:text="@string/reset_change_pass" />
    </RelativeLayout>
</ScrollView>

Answer

Doge picture Doge · Jul 26, 2012

This is truly strange, but it seems to be caused by android:layout_margin="32dp" within the RelativeLayout. Once I took it out the scroll worked properly.

Of course, because of this I had to add a bunch more margins to my form elements, but at least this is now fixed.