【问题标题】:RelativeLayout inside ScrollView with a button aligned to bottom of its parentScrollView 内的 RelativeLayout,其按钮对齐到其父级的底部
【发布时间】:2015-07-31 14:28:19
【问题描述】:

我有一个RelativeLayout,其结构采用“页眉/正文/页脚”样式。

  • 在标题部分我有一个TextView 显示当前片段的标题;

  • 正文包含一个ScrollView 元素,该元素包裹了一个包含其他元素的RelativeLayout

  • 最后,页脚只有一个Button

具体结构如下:

<RelativeLayout>
    <TextView />                <!-- the header -->

    <ScrollView>                <!-- the body -->
        <RelativeLayout>
            <!-- other elements -->
        </RelativeLayout>
    </ScollView>

    <Button />                  <!-- the footer -->

</RelativeLayout>

现在,我希望按钮始终位于主 RelativeLayout 的底部,因此我分配了属性 android:layout_alignParentBottom="true"

另外,ScrollView 必须填满整个正文,所以属性android:fillViewport="true" 已设置。

问题:事实上,页脚中的按钮越过了ScrollView 的最后部分,从而隐藏了包含正文的RelativeLayout 的最后元素。有什么办法可以解决这个问题吗?

【问题讨论】:

    标签: android android-layout alignment scrollview android-relativelayout


    【解决方案1】:

    尝试设置

    android:layout_above="@+id/id_of_your_button"
    

    在滚动视图上

    【讨论】:

    • 太棒了!它就像一个魅力。 :) 非常感谢。
    • @f_ficarola 很高兴我能帮上忙。如果它回答了您的问题,您可能会考虑接受答案
    • 是的,我只是在等待 StackOverflow 允许我接受您的回答! ;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-08
    • 2017-11-23
    • 1970-01-01
    • 1970-01-01
    • 2015-09-14
    • 2021-05-01
    相关资源
    最近更新 更多