I have the following structure in the layout file of my Android studio project, and I see unexplained left padding between the parent element (Toolbar) and it's immediate child element (LinearLayout).
Layout Text
<Toolbar
android:layout_width="fill_parent"
android:layout_height="600dp"
android:id="@+id/toolbar"
android:background="#313B45"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" android:orientation="vertical">
<ImageView
android:id="@+id/headerimage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:layout_gravity="left|top"
android:layout_weight="1"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="New Text"
android:id="@+id/textView"
android:scaleType="fitXY"
android:layout_gravity="left|top"
android:layout_weight="1"/>
</LinearLayout>
</Toolbar>
How can I remove this gap and have the child LinearLayout align fully with the parent Toolbar?
The above answer helped solve only a part, add these lines and it should work fine
notice that android:contentInsetLeft and app:contentInsetLeft are 2 separate things and both of them are needed
Add these lines to your toolbar layout : For API<=21 toolbar :
For API 21>= toolbar :
The left inset is caused by Toolbar's contentInsetStart which by default is 16dp.
Here's the full code :