你好,我有一个线性布局,里面放了一个片段小部件。我想把这个片段放在屏幕底部。因为以后页面可能会可滚动,所以我希望它始终锚定在屏幕底部。我该如何实现呢?
你好,我有一个线性布局,里面放了一个片段小部件。我想把这个片段放在屏幕底部。因为以后页面可能会可滚动,所以我希望它始终锚定在屏幕底部。我该如何实现呢?
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,它的底部应该停留在父级(activity)的底部,并且高度属性应该包裹片段内的其他UI组件,然后它就会粘在屏幕的父级底部。