2017-02-14 109 views
2

我有工具栏与图像作为标识,徽标居中。但是当我放置导航抽屉时,由于存在导航抽屉按钮,徽标向右移动。如何使徽标始终以工具栏中的导航抽屉按钮为中心?安卓工具栏图像居中与导航抽屉按钮

谢谢。

我的代码

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

发表您的醋栗输出的图像 –

回答

1

使用机器人:contentInsetLeft = “0dp” OR 机器人: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"> 
+0

它不工作 – user3851241

+0

始终“清洁与重新构建”制作后UI改变 – Pehlaj

1

试试这个布局:添加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> 
+0

商工具栏 – user3851241

+0

工具栏小工具里面成分没有layout_gravity有它自己的LayoutParams ......添加了重力分量在imageview和检查 – rafsanahmad007