Совместите нижнюю часть изображения с центром родителя - PullRequest
0 голосов
/ 25 января 2020

У меня есть CoordinatorLayout с LinearLayout, который содержит другие представления внутри него.

<?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>

Приведенный выше код выравнивает центр LinearLayout с центром CoordinatorLayout.

Я хочу выровнять нижнюю часть последней кнопки по центру CoordinatorLayout .

* Я использую CoordinatorLayout, потому что есть и RecyclerView для нижнего листа.

1 Ответ

1 голос
/ 25 января 2020

Это может быть уловка, но она должна работать:

<?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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...