【问题标题】:How to add space below scroll view如何在滚动视图下方添加空间
【发布时间】:2018-06-25 16:20:56
【问题描述】:

我在scroll view 中封装了一个活动,如下所示。

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    >

    <include layout="@layout/content_form" />

</ScrollView>

content_form 布局中有大约 15 个字段,问题是content_form 布局中的最后一项附在底部。

我需要在滚动视图下方添加一个边距,我已尝试为 scrollviewcontent_form 字段的最后一项提供边距,但没有任何效果。

我需要知道如何在使用scroll view时在页面底部添加边距。

【问题讨论】:

  • 在滚动视图的底部添加填充。你试过吗?或者给 content_form 的按钮添加一个视图
  • 能否添加content_form的代码

标签: android android-layout android-scrollview


【解决方案1】:

如果您希望滚动边距在内容内,最好将其添加到content_form。您应该能够通过在该布局中将paddingBottom 添加到您的父容器中来完成此操作,或者在与父底部对齐的最后一个视图中添加layout_marginBottom

【讨论】:

    【解决方案2】:

    这会在滚动视图中的最后一项下进行填充。可能对你有好处

     <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:paddingBottom="80dp"
        android:clipToPadding="false"
        android:layout_height="match_parent">
    

    【讨论】:

      【解决方案3】:

      您可以将 SpaceView 用于

      <Space
       android:layout_width="100dp"
       android:layout_height="match_parent"/>
      

      或者,

       <View
        android:layout_width="100dp"
        android:layout_height="match_parent"
        android:layout_weight="1"/>
      

      【讨论】:

        【解决方案4】:

        这里,你需要提供padding,而不是margin

        尝试为 ScrollView 提供填充。

        【讨论】:

          【解决方案5】:

          ScrollView 的直接子视图不是LinearLayout 时,我遇到了问题。所以请尝试将LinearLayout 作为scrollView 的直接子级并将&lt;include&gt; 布局放在LinearLayout 中。

          <ScrollView
             android:layout_width="match_parent"
             android:layout_height="match_parent">
          
             <LinearLayout
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:orientation="vertical">
          
                ... your layouts go here ...
          
             </LinearLayout>
          
          </ScrollView>
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2011-07-17
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2014-06-08
            • 1970-01-01
            相关资源
            最近更新 更多