如何在滚动视图下方添加空白区域

11

我已将一个活动包装在 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 底部添加一个视图。 - letsCode
你能添加content_form的代码吗? - Nawrez
5个回答

13

这将在滚动视图中的最后一个项目下添加填充。对你可能有好处。

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

12
如果您希望滚动边距在内容内部,最好将其添加到content_form中。您可以通过在该布局的父容器中添加paddingBottom或在最后一个与父容器底部对齐的视图上添加layout_marginBottom来实现此目的。

7
你可以使用 Space 或者 View 来实现这个目的。
<Space
 android:layout_width="100dp"
 android:layout_height="match_parent"/>

或者,

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

5

在这里,您需要使用填充(padding),而不是边距(margin)

尝试给ScrollView添加填充。


0

我曾经遇到过ScrollView在其直接子视图不是LinearLayout时表现不佳的问题。因此,请尝试将LinearLayout作为您的scrollView的直接子视图,并将<include>布局放置在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>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接