ScrollView doesn't scroll to the bottom
Asked Answered
G

7

54

I have a certain problem in my Activity. The ScrollView doesn't scroll down to the bottom.
I have a screenshot for you. enter image description here

If you look at the scrollbar of the scrollView, you can see that it's not scrolling down to the bottom.
Here's my XML layout of the scrollView:

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:fillViewport="true"
    android:layout_below="@+id/step2_header" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp" >

        <TextView
            android:id="@+id/step2_headerText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:gravity="center"
            android:text="@string/Schritt2"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/dark_blue"
            android:textStyle="bold|italic" />

        <ImageView
            android:id="@+id/step2_image"
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:layout_below="@+id/step2_headerText"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_marginTop="10dp"
            android:src="@drawable/menu_leiste" />

        <TextView
            android:id="@+id/step2_infoText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/step2_image"
            android:text="@string/step2Text"
            android:textAppearance="?android:attr/textAppearanceSmall" />

       <ImageView
            android:id="@+id/step2_but1Img"
            android:layout_width="match_parent"
            android:layout_height="35dp"
            android:layout_below="@+id/step2_infoText"
            android:layout_marginTop="10dp"
            android:src="@drawable/menu_leiste_selector" />

        <TextView
            android:id="@+id/step2_but1Text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/step2_but1Img"
            android:layout_alignParentLeft="true"
            android:layout_alignTop="@+id/step2_but1Img"
            android:layout_marginLeft="10dp"
            android:gravity="center"
            android:text="@string/step2But1Text"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/white" />

        <ImageView
            android:id="@+id/step2_but1ArrowImg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="3dp"
            android:layout_alignBottom="@+id/step2_but1Img"
            android:layout_alignParentRight="true"
            android:layout_alignTop="@+id/step2_but1Img"
            android:src="@drawable/location_web_site" />

        <ImageView
            android:id="@+id/step2_but2Img"
            android:layout_width="match_parent"
            android:layout_height="35dp"
            android:layout_below="@+id/step2_but1Img"
            android:layout_marginTop="10dp"
            android:src="@drawable/menu_leiste_selector" />

        <TextView
            android:id="@+id/step2_but2Text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/step2_but2Img"
            android:layout_alignParentLeft="true"
            android:layout_alignTop="@+id/step2_but2Img"
            android:layout_marginLeft="10dp"
            android:gravity="center"
            android:text="@string/step2But2Text"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/white" />

        <ImageView
            android:id="@+id/step2_but2ArrowImg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="3dp"
            android:layout_alignBottom="@+id/step2_but2Img"
            android:layout_alignParentRight="true"
            android:layout_alignTop="@+id/step2_but2Img"
            android:src="@drawable/location_web_site" />

    </RelativeLayout>

</ScrollView>

How can I fix it?

Gob answered 28/2, 2013 at 9:31 Comment(0)
E
156

The problem is android:layout_margin="10dp" in RelativeLayout of SrcollView

Replace

 <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp">

with

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp" >
Emulsifier answered 28/2, 2013 at 9:50 Comment(4)
difference between layout_margin and padding is that layout_margin is the margin for layout and padding is the margin for layout contentEmulsifier
Many people are having problems with ScrollView not scrolling to the bottom and a variety of issues were flagged (correctly or incorrectly) but this is the only posting I know that flagged this particular margin issue. You really saved my bacon here. In SO # 16880311 I posted a complete example of a layout broken by this very margin issue and a possible workaround; this might be useful to some. Briefly, the point is that you can emulate a margin with an extra, padded container.Lithoid
Adding some padding to the layout right under the ScrollView works for me. ThanksMusil
While adding padding works it seems like a bit of a cludge to me. A better solution is to replace "ScrollView" with "NesdtedScrollView".Fluorite
L
7

use in scrollView xml

android:paddingBottom="10dp"

it'll shift content of scroll view to 10 dp upward not the VIEW.

Lenten answered 28/2, 2013 at 9:34 Comment(2)
Adding padding to the layout right under scrollView works. Adding to the scrollView does not work.Musil
@medphys_muc adding an empty view at the end will fix the issue. Refer the link - #30283080Dol
F
7

Try NestedScrollView instead.

I have had this problem several times myself and while simply adding extra padding to the bottom to hide the fact that the scroll view is going 'behind' the bottom bar works, a better solution is to use a NestedScrollView as mentioned in this answer: https://mcmap.net/q/339630/-scrollview-not-scrolling-bottom-completely

Fluorite answered 14/10, 2019 at 23:12 Comment(0)
P
4

For me I have another specific solution if the parent layout of the ScrollView is ConstraintLayout. If so, we don't need to set the padding or margin.

<androidx.constraintlayout.widget.ConstraintLayout 
....>
    <ScrollView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toBottomOf="<if there is any element before this this scrollview >">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >
Photon answered 14/12, 2018 at 1:11 Comment(0)
V
0

For me, setting explicit height to some of my internal elements helped.

Valency answered 10/10, 2018 at 22:50 Comment(0)
C
0

I was suffering from the same problem. Try to add more padding to the bottom of scrollView.It works for me.

android:paddingBottom="50dp"
Charyl answered 6/6, 2019 at 17:40 Comment(0)
A
-3

This may be problem with your layout design. if you add the margin for the view then it will be visible clearly. so

In scrollview add

android:layout_marginBottom="30dp"
Anticlinorium answered 28/2, 2013 at 9:34 Comment(3)
is scrollview is your parent?Anticlinorium
try giving margin bottom to your relative layout.Anticlinorium
this didn't help me. The problem is android:layout_margin="10dp" in relativelayoutGob

© 2022 - 2024 — McMap. All rights reserved.