ScrollView不会滚动到底部

时间:2013-02-28 09:31:40

标签: android xml scrollview

我的活动中遇到了一些问题。 ScrollView不会向下滚动到底部 我有截图给你。 enter image description here

如果查看scrollView的滚动条,可以看到它没有向下滚动到底部。
这是我的scrollView的XML布局:

<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>

我该如何解决?

7 个答案:

答案 0 :(得分:117)

问题是在SrcollView的RelativeLayout中 android:layout_margin =“10dp”

替换

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

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

答案 1 :(得分:6)

在scrollView xml中使用

android:paddingBottom="10dp"

它会将滚动视图的内容向上移动10 dp而不是VIEW。

答案 2 :(得分:2)

对我来说,如果ScrollView的父级布局为ConstraintLayout,则我还有另一个特定的解决方案。如果是这样,我们不需要设置填充或边距。

<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" >

答案 3 :(得分:2)

改为尝试NestedScrollView

我本人几次遇到这个问题,同时只是简单地在底部添加了额外的填充以隐藏滚动视图位于底部条“后面”的事实,更好的解决方案是使用此答案中提到的NestedScrollView: https://stackoverflow.com/a/36871385/6573127

答案 4 :(得分:0)

对我来说,为某些内部元素设置显式高度很有帮助。

答案 5 :(得分:0)

我遇到了同样的问题。尝试在scrollView的底部添加更多填充。它对我有用。

android:paddingBottom="50dp"

答案 6 :(得分:-2)

这可能是您的布局设计有问题。如果你为视图添加边距,那么它将清晰可见。所以

在scrollview中添加

android:layout_marginBottom="30dp"
相关问题