【问题标题】:Align fragment on bottom of screen在屏幕底部对齐片段
【发布时间】:2018-11-30 21:01:55
【问题描述】:

您好,我有一个线性布局,其中放置了一个片段小部件。我正在尝试让片段显示在屏幕底部。该页面将来可能可以滚动,因此我希望它始终固定在屏幕底部。我怎样才能做到这一点?

【问题讨论】:

  • 似乎工作正常。 ty
  • 那是什么问题?
  • 哦,太好了,我应该投票并接受答案评论:P 不是吗?

标签: android user-interface


【解决方案1】:

您必须使用RelativeLayout。像这样的:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/bottom_fragment" >
    </ScrollView>

    <fragment
        android:id="@+id/bottom_fragment"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_alignParentBottom="true" >
    </fragment>

</RelativeLayout>

【讨论】:

    【解决方案2】:

    要通过约束布局实现这一点,请使用下面的行。

    app:layout_constraintBottom_toBottomOf="parent"

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:paddingBottom="@dimen/padding_16dp"
        app:layout_constraintBottom_toBottomOf="parent"
        android:paddingTop="@dimen/padding_16dp">
            //UI Components..
    </android.support.constraint.ConstraintLayout>
    

    它看起来像 bottom_sheet_fragment。这是xml文件的根标签。我对 ConstraintLayout 说,它的底部应该留在 parent(activity) 底部,height 属性应该将其他 UI 组件包裹在 Fragment 内,然后它会粘在屏幕的父级底部。

    【讨论】:

    • 你能再解释一下吗?
    • 这个答案有点含糊,请多解释一下
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-11
    • 1970-01-01
    • 2011-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多