Android: ScrollView not scrolling with keyboard out
Asked Answered
T

12

58

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?

Tetrasyllable answered 11/3, 2013 at 16:12 Comment(1)
for Android 5, check out this related post: Android - adjust scrollview when keyboard is up for android 5.0 (lollipop)Rejoin
T
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.

Tetrasyllable answered 15/3, 2013 at 19:38 Comment(3)
layout_above whatever view you want to have fixed at the bottem of the screenTetrasyllable
what if no fixed view at bottom?Coltoncoltsfoot
Doesn't work if the ScrollView only takes up a part of the screen. If you have a layout at the bottom of your activity that acts like a footer, this solution will not work.Stivers
O
68

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.

Obsess answered 12/8, 2013 at 10:14 Comment(1)
this property blocked the scrolling while I was editing text inside an editText. I removed this property and now scrolling works. Not sure why, but none of the solutions in this thread worked for me, only deleting this line.Millipede
T
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.

Tetrasyllable answered 15/3, 2013 at 19:38 Comment(3)
layout_above whatever view you want to have fixed at the bottem of the screenTetrasyllable
what if no fixed view at bottom?Coltoncoltsfoot
Doesn't work if the ScrollView only takes up a part of the screen. If you have a layout at the bottom of your activity that acts like a footer, this solution will not work.Stivers
D
29

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.

Deer answered 12/9, 2017 at 8:49 Comment(0)
S
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.

Sentience answered 17/11, 2014 at 10:55 Comment(0)
A
6

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

Aedes answered 8/7, 2020 at 5:28 Comment(0)
G
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.

Gravitt answered 16/8, 2019 at 2:34 Comment(1)
Thanks your solution helped me , I had similar problem but I added fullscreen in styles.xmlCurule
C
3

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

<item name="android:windowFullscreen">true</item>
Curule answered 27/1, 2020 at 5:20 Comment(1)
Works as expected, Thanks.Tortuosity
A
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.

Almsman answered 5/2, 2015 at 10:18 Comment(0)
B
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.

Buddy answered 18/7, 2020 at 11:2 Comment(0)
C
0

I'm facing the same problem.

Before changing

android:windowSoftInputMode="adjustResize|adjustPan"

After changing

android:windowSoftInputMode="adjustResize"

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

Comber answered 20/10, 2023 at 8:55 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Kharif
I
-2

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

Idyllist answered 10/7, 2017 at 4:30 Comment(0)
N
-7
<activity 
    android:windowSoftInputMode="adjustResize"
>

try this In android manifest ..

Newhouse answered 22/4, 2018 at 16:47 Comment(1)
That answer was already given by Ciprian in 2013Calcariferous

© 2022 - 2024 — McMap. All rights reserved.