Android 将视图底部与父视图的中心对齐

Android 将视图底部与父视图的中心对齐,android,android-coordinatorlayout,Android,Android Coordinatorlayout,我有一个带有线性布局的CoordinatorLayout,其中包含其他视图 <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_heigh

我有一个带有线性布局的CoordinatorLayout,其中包含其他视图

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
    android:layout_gravity="center"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button 1"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button 2"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Last Button"/>
</LinearLayout>

上述代码将线性布局的中心与坐标布局的中心对齐

我想将最后一个按钮的底部与CoordinatorLayout的中心对齐


*我使用CoordinatorLayout,因为还有一个底部板材回收视图。

这可能是一个技巧,但它应该可以工作:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <LinearLayout
        android:layout_gravity="top|center_horizontal"
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_anchor="@id/hiddenGuidelineView"
        app:layout_anchorGravity="bottom|center_horizontal">

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Button 1"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Button 2"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Last Button"/>

    </LinearLayout>

    <View
        android:id="@+id/hiddenGuidelineView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_gravity="center_vertical"/>

</android.support.design.widget.CoordinatorLayout>