对齐屏幕底部的片段

时间:2013-08-12 16:00:01

标签: android user-interface

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

2 个答案:

答案 0 :(得分:4)

您必须使用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>

答案 1 :(得分:0)

要使用约束布局实现此目的,请使用以下行。

  

app:layout_constraintBottom_toBottomOf =“父母”

<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说,它的底部应该留在parents(活动)底部,而height属性应该将其他UI组件包裹在片段内,然后粘贴到屏幕的父底部。

相关问题