【问题标题】:ScrollView doesn't scroll to the bottomScrollView 不滚动到底部
【发布时间】:2013-02-14 10:23:34
【问题描述】:

我在我的活动中遇到了某些问题。 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>

我该如何解决?

【问题讨论】:

    标签: android xml scrollview


    【解决方案1】:

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

    替换

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

    【讨论】:

    • layout_margin和padding的区别在于layout_margin是layout的margin,padding是layout内容的margin
    • 许多人在 ScrollView 无法滚动到底部时遇到问题,并且标记了各种问题(正确或错误),但这是我所知道的唯一标记此特定边距问题的帖子。你真的在这里救了我的培根。在 SO # 16880311 中,我发布了一个完整的布局示例,该示例被这个边距问题和可能的解决方法破坏了;这可能对某些人有用。简而言之,重点是您可以使用额外的填充容器来模拟边距。
    • 像魅力一样工作。你是天才。
    • 在 ScrollView 正下方的布局中添加一些填充对我有用。谢谢
    • 虽然添加填充工作,但对我来说似乎有点混乱。更好的解决方案是将“ScrollView”替换为“NesdtedScrollView”。
    【解决方案2】:

    在scrollView xml中使用

    android:paddingBottom="10dp"
    

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

    【讨论】:

    • 在 scrollView 正下方的布局中添加内边距有效。添加到 scrollView 不起作用。
    • @medphys_muc 在最后添加一个空视图将解决问题。请参阅链接 - stackoverflow.com/questions/30282580/…
    【解决方案3】:

    改用NestedScrollView

    我自己也遇到过几次这个问题,虽然只是在底部添加额外的填充以隐藏滚动视图在底部栏“后面”起作用的事实,但更好的解决方案是使用本文中提到的 NestedScrollView答案:https://stackoverflow.com/a/36871385/6573127

    【讨论】:

      【解决方案4】:

      如果 ScrollView 的父布局是 ConstraintLayout,我有另一个特定的解决方案。如果是这样,我们就不需要设置 padding 或 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" >
      

      【讨论】:

        【解决方案5】:

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

        【讨论】:

          【解决方案6】:

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

          android:paddingBottom="50dp"
          

          【讨论】:

            【解决方案7】:

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

            在滚动视图中添加

            android:layout_marginBottom="30dp"
            

            【讨论】:

            • scrollview 是你的父母吗?
            • 尝试给你的相对布局留底边距。
            • 这对我没有帮助。问题是相对布局中的 android:layout_margin="10dp"
            猜你喜欢
            • 1970-01-01
            • 2020-03-26
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2011-02-19
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多