Как установить гравитацию для панели инструментов внутри CollapsingToolbarLayout? - PullRequest
0 голосов
/ 14 октября 2019

У меня есть панель инструментов, которая хочет установить гравитацию внизу внутри CollapsingToolbarLayout, например, как это делал Samsung Notes.

Я попытался установить гравитацию макета снизу, но после этого CollapsingToolbarLayout не отображается.

без android:layout_gravity="bottom"

https://imgur.com/a/jMO5ndg

с android:layout_gravity="bottom" Скрывает CollapsingToolbarLayout https://imgur.com/a/vIh7WM3

Мой макет

<com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="240dp"
        android:backgroundTint="@color/white"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:contentScrim="@color/white"
            app:expandedTitleGravity="center"
            app:layout_scrollFlags="exitUntilCollapsed|scroll"
            app:title="Personal Tasks">

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                style="@style/LightActionBarTheme"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:layout_gravity="bottom"
                app:layout_collapseMode="pin"
                app:titleTextColor="@color/colorPrimary" />
        </com.google.android.material.appbar.CollapsingToolbarLayout>
    </com.google.android.material.appbar.AppBarLayout>

Я хотел, чтобы в меню параметров вместе с кнопкой домашнего действия на панели инструментов отображалась сила тяжести, не скрывая CollapsingToolbarLayout. Ожидаемый результат, как Samsung Notes:

https://imgur.com/a/Cq15WsQ

1 Ответ

0 голосов
/ 14 октября 2019

попытайтесь поместить ваш элемент CollapsingToolbarLayout в RelativeLayout:

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.appbar.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/appBarLayout"
    android:layout_width="match_parent"
    android:layout_height="240dp"
    android:backgroundTint="@color/cardview_light_background"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <com.google.android.material.appbar.CollapsingToolbarLayout
        android:id="@+id/collapsingToolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="exitUntilCollapsed|scroll"
        >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_collapseMode="pin"
            >

            <TextView
                android:layout_centerInParent="true"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Personal Tasks"/>

            <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            style="@style/LightActionBarTheme"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
             android:layout_alignParentBottom="true"
            app:titleTextColor="@color/colorPrimary" />

        </RelativeLayout>

    </com.google.android.material.appbar.CollapsingToolbarLayout>


</com.google.android.material.appbar.AppBarLayout>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...