Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: ScrollView not scrolling with keyboard out

I've got a layout with some views, from which one is an EditText. The layout easily fits on one page, BUT, when the soft keyboard is out, the layout doesn't scroll. Here's a recap of my layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background" >

    <ScrollView
        android:id="@+id/ScrollView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true" >

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

            <CheckBox/>

            <TextView/>

            <LinearLayout>
                <EditText>
                    <requestFocus />
                </EditText>
            </LinearLayout>

            <TextView/>

            <LinearLayout>
                <Spinner/>
            </LinearLayout>

        </LinearLayout>

    </ScrollView>

    <Button
        android:layout_alignParentBottom="true" />

</RelativeLayout>

And in my manifest I have declared the attribute:

android:windowSoftInputMode="adjustResize|stateHidden"

Does anyone know why it doesn't work and how to make sure it does work?

Thanks in advance!

like image 886
Xander Avatar asked Mar 11 '13 16:03

Xander


4 Answers

I had the same problem and I checked my activity in the manifest, and the reason why it wasn't working is because I didn't use this property:

android:windowSoftInputMode="adjustResize"

Now it works great and no need to do additional anchors.

like image 90
Ciprian Avatar answered Oct 24 '22 09:10

Ciprian


Okay, apparently the ScrollView's android:layout_height mustn't be set to wrap_content. I set it to match_parent and set the android:layout_above to the button on the bottom of the page.

Don't ask me why, but this fixed the issue.

like image 30
Xander Avatar answered Oct 24 '22 09:10

Xander


In my case, nothing of the above worked.

I had item name="android:windowTranslucentStatus">true</item> in my theme. And it was fixed by setting android:fitsSystemWindows="true" in the parent layout where is my scrollview.

like image 27
giorgos.nl Avatar answered Oct 24 '22 09:10

giorgos.nl


Add android:windowSoftInputMode="stateHidden|adjustResize" to your tag in AndroidManifest.xml file. This will cause the screen to be resized to the left over space after the soft keyboard is shown. So, you will be able to scroll easily.

like image 13
Rajesh Hegde Avatar answered Oct 24 '22 10:10

Rajesh Hegde