Android ScrollView refuses to scroll to bottom
Asked Answered
P

4

28

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>
Person answered 26/7, 2012 at 1:2 Comment(1)
This also happens with LinearLayout. Thank you for providing this thread!Badminton
P
41

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.

Person answered 26/7, 2012 at 1:55 Comment(4)
This is true. If your layout inside the ScrollView has margins you will not be able to scroll all the way to the bottom. For my case I could just put the margin in the root layout as I had a LinearLayout containing a scrollview and a button.Farlie
Thanks for your auto-response, it saved me from a lot of time !Septempartite
padding on the scrollview would prevent the need to margin every element?Lawgiver
Padding on the child of my ScrollView (LinearLayout) ended up being the optimal solution for me. Shifting the margin to the ScrollView itself works in a way, but causes the scroll bar to have a margin with the edge of the screen. Thanks!Willaims
T
13

I had the same issue and I fixed it by using padding in the ScrollView instead of margin in RelativeLayout.

So, remove android:layout_margin="32dp" from RelativeLayout(the child of ScrollView) and add android:padding="32dp" to the ScrollView.

Tomchay answered 7/8, 2013 at 12:32 Comment(3)
This was the more appropriate solution than to go and divide out the margin in the child elements. The margin just needs to be placed in the appropriate location; the ScrollView itself instead of the layout element it surrounds.Pinkston
just said this without noticing the comment or the date of this post xDLawgiver
In case this helps someone else, I also encountered this bug when I put the padding on the ScrollView. The only thing that worked for me was putting padding on the ScrollView's child.Lactoscope
R
2

Making status bar transparent in lollipop and above was creating the problem for me. Setting

android:fitsSystemWindows="true"
to the parent view of layout containing scrollView solved the issue.
Ratio answered 23/2, 2018 at 8:7 Comment(1)
This needs more likes :) Worked much better than fiddling around with margins etcAdeline
A
0

I just had this problem with an app and found out that it was due to the ScrollView layout_height being set to wrap content. The issue is that if you have enough content to need a ScrollView, you don't want to wrap the content because the bottom of the ScrollView is off the screen by some arbitrary amount. I didn't have enough data to be affected by this as I didn't need a ScrollView until the keyboard popped up. By the looks of it, the OP was in the same situation.

Now, once the keyboard pops up, the bottom of the ScrollView is raised the same amount as the height of the keyboard and ends up below the top of the keyboard by the same arbitrary amount that it was below the bottom of the visible screen.

Ultimately, my fix was to bind the top of the ScrollView to my toolbar and then right-click the ScrollVIew in the tree and select 'center vertically' (not in parent option). Now works like a charm. The layout_height should automatically go to 0dp.

Acadian answered 2/10, 2017 at 6:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.