Android toolbar image centered on NAV drawer button

I have a toolbar with an image as the logo and the logo is centered. However, when I place the navigation drawer, the logo moves to the right because there is a navigation drawer button. How do I always center the logo with the navigation drawer button in the toolbar?

thank you.

My password

<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>

resolvent:

Try the following layout: Android: Layout_ Gravity = "center_horizontal" added to 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>

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>