【发布时间】:2018-11-30 21:01:55
【问题描述】:
您好,我有一个线性布局,其中放置了一个片段小部件。我正在尝试让片段显示在屏幕底部。该页面将来可能可以滚动,因此我希望它始终固定在屏幕底部。我怎样才能做到这一点?
【问题讨论】:
-
似乎工作正常。 ty
-
那是什么问题?
-
哦,太好了,我应该投票并接受答案评论:P 不是吗?
您好,我有一个线性布局,其中放置了一个片段小部件。我正在尝试让片段显示在屏幕底部。该页面将来可能可以滚动,因此我希望它始终固定在屏幕底部。我怎样才能做到这一点?
【问题讨论】:
您必须使用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>
【讨论】:
要通过约束布局实现这一点,请使用下面的行。
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 内,然后它会粘在屏幕的父级底部。
【讨论】: