![](/img/trans.png)
[英]Adding views to Toolbar removes the programatically set title when using the CollapsingToolbarLayout
[英]How to set gravity for Toolbar inside CollapsingToolbarLayout?
我有一個工具欄,希望它在 CollapsingToolbarLayout 內將重力設置為底部,就像三星筆記是如何做到的一樣。
我嘗試將布局重力設置為底部,但這樣做會使 CollapsingToolbarLayout 不顯示。
沒有android:layout_gravity="bottom"
使用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。 預計 Output 像三星 注意:
嘗試將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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.