Toolbar is not in the center of AppBarLayout

I used this example to build a layout with two navigation windows:

http://v4all123.blogspot.de/2016/03/simple-example-of-navigation-view-on.html

It works great. But also in the demo on this site, you can see that the toolbar is not 100% in the middle. The left button has more space on the left than the right button on the right border.

Take a look at the screenshot from Android Studio.

I tried to center each view, but the only way to get the same space left and right is to add padding to the right. But I can't believe this is the only way to get to the middle of the layout.

Is there another trick to center buttons and views on the toolbar?

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false"
tools:context=".frontend.MainActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent"
    app:elevation="0dp"
    android:gravity="center">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:layout_gravity="center_horizontal"
        android:gravity="center_horizontal"
        app:popupTheme="@style/AppTheme.PopupOverlay">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center">

            <ImageButton
                android:id="@+id/menuLeft"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:src="@drawable/ic_menu_white_24dp"
                android:tint="@color/colorPrimary" />
            <TextView
                android:id="@+id/headerLine"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:text="Example application"
                android:textSize="20dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:textAlignment="center"
                android:maxLines="1"
                android:lines="1"
                android:layout_toRightOf="@+id/menuLeft"
                android:layout_toLeftOf="@+id/menuRight"
                android:singleLine="true"
                android:ellipsize="end"
                android:textAppearance="@style/TextAppearance.AppCompat.Body1"
                android:textColor="@color/headerTextColorPrimary" />
            <ImageButton
                android:id="@+id/menuRight"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true"
                android:src="@drawable/ic_menu_white_24dp"
                android:tint="@color/colorPrimary" />
        </RelativeLayout>
    </android.support.v7.widget.Toolbar>

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

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

      

0


source to share


2 answers


add

app:contentInsetStart="0dp" 

      



on the toolbar. This will remove the add-on on the left side of the toolbar.

+1


source


Here's already answered. Find android:contentInsetLeft="0dp"

and    android:contentInsetStart="0dp"

in the following link. This will work for you.



fooobar.com/questions/43843 / ...

0


source







All Articles