ScrollView doesn't scroll to the bottom
AndroidXmlScrollviewAndroid Problem Overview
I have a certain problem in my Activity. The ScrollView doesn't scroll down to the bottom.
I have a screenshot for you.
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?
Android Solutions
Solution 1 - Android
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" >
Solution 2 - Android
use in scrollView xml
android:paddingBottom="10dp"
it'll shift content of scroll view to 10 dp upward not the VIEW.
Solution 3 - Android
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://stackoverflow.com/a/36871385/6573127
Solution 4 - Android
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" >
Solution 5 - Android
For me, setting explicit height to some of my internal elements helped.
Solution 6 - Android
I was suffering from the same problem. Try to add more padding to the bottom of scrollView.It works for me.
android:paddingBottom="50dp"
Solution 7 - Android
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"