android-在屏幕底部对齐片段

提问

嗨,我有一个线性布局,其中放有一个片段小部件.我正在尝试将片段显示在屏幕底部.该页面将来可能会滚动,因此我希望它始终固定在屏幕底部.我该如何实现?

最佳答案

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