Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

match_parent not working for Toolbar with layout inside

android studio 2.0 beta5

I have noticed that when I include a layout inside a Toolbar the left edge of that layout never aligns to the left edge of the toolbar's parent even though I have set both to match_parent.

This is my xml snippet

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:background="@android:color/transparent"
    android:theme="@style/ThemeOverlay.AppCompat.Dark">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp">
    </LinearLayout>

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

This is a screenshot of what is happening.

enter image description here

As you can see from the above picture the LinearLayout doesn't match the parent. I have also tried FrameLayout and RelativeLayout as well with the same result.

I am not sure if this is a bug with android studio or this space on the left is reserved for something.

Even when I run the app on a real device it doesn't match the parent either.

Many thanks for any suggestions

like image 413
ant2009 Avatar asked Feb 23 '16 10:02

ant2009


1 Answers

Just put android:contentInsetStart="0dp" inside:

<android.support.v7.widget.Toolbar....

contentInsetStart="0dp"

...</>
like image 173
Leonid Veremchuk Avatar answered Oct 17 '22 17:10

Leonid Veremchuk