簡體   English   中英

折疊工具欄標題未居中

[英]Collapsing Toolbar title not centered

我的應用程序包含一個帶有標題的折疊工具欄。 標題在展開時為 centerend,在折疊時應保持居中。 對於下面的布局,我的設備在折疊時不會將標題居中,而是將其向右移動一點。 我必須改變什么才能讓它保持居中? 如果有幫助,我當然也可以添加圖像。

我的布局:

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

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:expandedTitleGravity="center|bottom"
            app:title="Test"
            app:collapsedTitleGravity="center"
            app:expandedTitleMarginBottom="56dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:toolbarId="@+id/toolbar">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:layout_marginBottom="48dp"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:fillViewport="true"
        android:layout_gravity="fill_vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">>

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

這是它看起來像擴展

正如你在這張圖片上看到的,它沒有居中,而是稍微移到了右側

將內容相關屬性設置為 0dp 會對您有所幫助。 這是我的工作工具欄條目。

<androidx.appcompat.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    app:contentInsetLeft="0dp"
                    android:contentInsetLeft="0dp"
                    app:contentInsetStartWithNavigation="0dp"
                    app:contentInsetStart="0dp"
                    android:contentInsetStart="0dp"
                    app:theme="@style/YourTheme"
                    android:gravity="center_horizontal"
                    android:layout_height="?attr/actionBarSize"
                    app:layout_collapseMode="pin"
                    app:titleMargin="0dp" />

希望它會有所幫助:)

這是因為右上角的后退按鈕。 解決方案是在工具欄中添加 marginEnd 。

<com.google.android.material.appbar.CollapsingToolbarLayout
    android:id="@+id/htab_collapse_toolbar"
    android:layout_width="match_parent"
    android:layout_height="110dp"
    app:expandedTitleMargin="@dimen/margin_15"
    app:collapsedTitleTextAppearance="@style/test1"
    app:expandedTitleTextAppearance="@style/test"
    app:collapsedTitleGravity="center_horizontal"
    app:layout_scrollFlags="scroll|exitUntilCollapsed"
    android:fitsSystemWindows="true"
    app:title="Send money">
    <androidx.appcompat.widget.Toolbar
        android:id="@+id/htab_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:layout_marginEnd="85dp"
        android:layout_gravity="top"
        app:layout_collapseMode="pin"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</com.google.android.material.appbar.CollapsingToolbarLayout>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM