57

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?

starball
  • 20,030
  • 7
  • 43
  • 238
Xander
  • 5,487
  • 14
  • 49
  • 77
  • 2
    for Android 5, check out this related post: [Android - adjust scrollview when keyboard is up for android 5.0 (lollipop)](http://stackoverflow.com/questions/27167176/android-adjust-scrollview-when-keyboard-is-up-for-android-5-0-lollipop) – Richard Le Mesurier Nov 27 '15 at 07:49

11 Answers11

67

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.

Deepzz
  • 4,573
  • 1
  • 28
  • 52
Ciprian
  • 2,879
  • 3
  • 28
  • 28
38

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.

Xander
  • 5,487
  • 14
  • 49
  • 77
27

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.

giorgos.nl
  • 2,704
  • 27
  • 36
13

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.

Rajesh Hegde
  • 2,702
  • 1
  • 18
  • 23
5

In my case any of the solution above does not work until I REMOVE

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

in my activity, I use that code to get a full screen display. Maybe for certain cases, try to remove any setup of full screen to make any of the above solution works.

5

If your First Fragment Scroll perfectly and the second fragment did not scroll then you should use the second fragment replace and do below things

1.Add in ScrollView

android:fillViewport="true"
android:fitsSystemWindows="true"

2.Add in Manifest

android:windowSoftInputMode="adjustResize|stateVisible"

If you add fragment then my suggestion is you need to Replace the Fragment

AgentP
  • 6,261
  • 2
  • 31
  • 52
3

In my case I had to Remove the following property from my style to make it work .

<item name="android:windowFullscreen">true</item>
Manohar
  • 22,116
  • 9
  • 108
  • 144
1

My problem was with a HorizontalScrollView. In my case I had to set HorizontalScrollView to:

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

And remove:

 android:layout_above="@+id/closeButton"
 android:layout_below="@+id/logo"

In the AndroidManifest.xml the activity is set to:

android:windowSoftInputMode=""

I hope this helps anyone comming across this weird bug.

gtsouk
  • 5,208
  • 1
  • 28
  • 35
0

In my case, what solved this was setting a missing constraint in the Bottom. My ScrollView had top, right, and left constraints, but no bottom one. After restricting it from all sides, it started to overlap the above textview, which prompted me to try putting the height to 0dp, and that seemed to solve the problem.

sbenati
  • 471
  • 4
  • 8
-2

Try to set ScrollView as your parent layout. It works like charm for me!

-6
<activity 
    android:windowSoftInputMode="adjustResize"
>

try this In android manifest ..

  • 1
    That answer was already given by [Ciprian in 2013](https://stackoverflow.com/a/18184481/3004518) – auhmaan Jul 19 '18 at 15:08