0

Following is the layout of the Toolbar I am using, but I am getting a strange gap towards the left side of the first ImageView (the gap between the left edge of the screen and the right edge of the left-ImageView). The question is why, and how can I get rid of it?

enter image description here

I even tried to set a android:padding="0dp" to LinearLayout and a android:layout_margin="0dp" to the relevant ImageView, but that doesn't seem to work. I am using Material Design if that matters.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#F4FA58"
    android:elevation="4dp" >

    <LinearLayout 
        android:id="@+id/appBar_linearLayout"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:radius="25dp"
        android:background="#B45F04"
        android:padding="0dp" >

        <ImageView 
            android:id="@+id/appBar_imageView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_action_back"
            android:contentDescription="@string/appBar_imageView_contentDescription"
            android:layout_margin="0dp" />

        <include
            android:id="@+id/appBar_searchView"
            layout="@layout/searchview" />

        <ImageView 
            android:id="@+id/appBar_imageViewOne"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_action_cancel"
            android:contentDescription="@string/appBar_imageViewOne_contentDescription" />

    </LinearLayout>

</android.support.v7.widget.Toolbar>
Solace
  • 8,612
  • 22
  • 95
  • 183

1 Answers1

1

I've seen this problem before, and figured out how to fix it by doing the following:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#F4FA58"
    android:elevation="4dp"
    app:contentInsetLeft="0dp"
    app:contentInsetStart="0dp" >

Notice the contentInsetLeft I added. There is a default 16dp padding set by the toolbar you remove by adding the 0dp. Hope this helps, let me know if it doesn't work!

EDIT: Also, check out this link I found from someone else's question Android API 21 Toolbar Padding

Community
  • 1
  • 1
Lucas Crawford
  • 3,078
  • 2
  • 14
  • 25
  • Thank you so very much, this works. `contentInset`s did occur to me, but I didn't try because apparently the padding/inset seemed to be within the `LinearLayout` (I know it was in the Toolbar (because this solution works), but then there should have been a gap between the left edge of the screen and the left edge of the LinearLayout (the yellow part), isn't it :s). But this works and thank you so very much. – Solace Aug 08 '15 at 04:19
  • You forgot to add the `xmlns:app` to that xml, it can confuse any future visitors, so please add it =) Thank you again. – Solace Aug 08 '15 at 04:20
  • Hey no problem at all, I'm glad I could help. Yeah I'll add that bit now :P – Lucas Crawford Aug 08 '15 at 04:20