首页 > 解决方案 > 如何在保持菜单结束的同时将 AndroidX 工具栏文本居中对齐?

问题描述

我想将我ToolBar Text的中心对齐,同时将三点菜单保留在最后,但我找不到办法做到这一点。每当我改变重力时,整个重力都会发生变化。

我的布局图片:布局图像

布局代码:

    <com.google.android.material.appbar.AppBarLayout
            android:id="@+id/appBarLayout"
            android:layout_width="match_parent"
            android:layout_height="56dp"
            android:layout_alignParentStart="true"
            android:layout_gravity="center|top"
            android:background="#fff"
            app:elevation="0dp">

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/main_toolbar"
                android:layout_width="wrap_content"
                android:layout_height="?attr/actionBarSize"
                android:layout_gravity="end"
                android:background="#fff"
                app:title="CENTER">

            </androidx.appcompat.widget.Toolbar>

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

标签: androidandroid-layout

解决方案


将它们的宽度设置match_parent为。


推荐阅读