简体   繁体   English

Android工具栏图片以Nav Drawer按钮为中心

[英]Android Toolbar Image Centered with Nav Drawer button

I have toolbar with image as logo, the logo was centered. 我有工具栏,图像作为徽标,徽标居中。 But when I put navigation drawer, the logo moved to right because there was navigation drawer button. 但是当我放置导航抽屉时,徽标向右移动,因为有导航抽屉按钮。 How to make the logo always centered with navigation drawer button in toolbar? 如何使徽标始终以工具栏中的导航抽屉按钮为中心?

Thanks. 谢谢。

My code 我的代码

<android.support.design.widget.AppBarLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.v7.widget.Toolbar
       android:id="@+id/toolbar"
       android:layout_width="match_parent"
       android:layout_height="?attr/actionBarSize"
       android:background="?attr/colorPrimary"
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

           <ImageView
              android:layout_width="match_parent"
              android:layout_height="25dp"
              android:src="@drawable/logo"/>

     </android.support.v7.widget.Toolbar>

     <android.support.design.widget.TabLayout
         android:id="@+id/tabs"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:background="?attr/colorPrimaryDark"
         app:tabGravity="fill"
         app:tabMode="fixed" />

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

try this layout: add android:layout_gravity="center_horizontal" to the Imageview 试试这个布局:将android:layout_gravity="center_horizontal"Imageview

<android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

            <ImageView
                android:layout_width="match_parent" //change this to wrap_content
                android:layout_height="25dp"
                android:layout_gravity="center_horizontal"
                android:src="@drawable/logo"/>
        </android.support.v7.widget.Toolbar>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/colorPrimaryDark"
            app:tabGravity="fill"
            app:tabMode="fixed" />
    </android.support.design.widget.AppBarLayout>

Use android:contentInsetLeft="0dp" OR android:contentInsetStart="0dp" with Toolbar 使用android:contentInsetLeft =“0dp”android:contentInsetStart =“0dp”与工具栏

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    android:contentInsetLeft="0dp">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM