LinearLayout inside ToolBar does not match parent

I put LinearLayout1 in the ToolBar. Then five more LinearLayouts in LinearLayout1. Every LinearLayout child has an ImageView. My problem here is that LinearLayout1 does not match the width of the parent. This I showed in the image (in the red circle). Black is the background that I provided with the ToolBar.

<android.support.v7.widget.Toolbar
    android:id="@+id/featured_bottomToolbar"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_gravity="bottom"
    android:background="#000000"
    android:layout_alignParentBottom="true">


    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="0dp"
            android:layout_weight="2"
            android:layout_height="match_parent">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/menu_black_featured"
                android:id="@+id/imageView" />
        </LinearLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="0dp"
            android:layout_weight="2"
            android:layout_height="match_parent">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/menu_grey_justin2"
                android:id="@+id/imageView2" />
        </LinearLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="0dp"
            android:layout_weight="2"
            android:layout_height="match_parent">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/menu_grey_designers"
                android:id="@+id/imageView3" />
        </LinearLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="0dp"
            android:layout_weight="2"
            android:layout_height="match_parent">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/menu_grey_categories"
                android:id="@+id/imageView4" />
        </LinearLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="0dp"
            android:layout_weight="2"
            android:layout_height="match_parent">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/meny_grey_more2"
                android:id="@+id/imageView5" />
        </LinearLayout>

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

The exit that I have.

enter image description here

+4
source share
4 answers

Add the Toolbarfollowing properties to your element .

app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"

The default contentInsetStartvalue is 16dp. You need to install it on 0.

+37
source
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/featured_bottomToolbar"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_gravity="bottom"
        android:background="#000000"
        app:contentInsetLeft="0dp"
        app:contentInsetStart="0dp"
        android:layout_alignParentBottom="true">


        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="0dp"
                android:layout_weight="2"
                android:layout_height="match_parent">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:src="@drawable/menu_black_featured"
                    android:id="@+id/imageView" />
            </LinearLayout>

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="0dp"
                android:layout_weight="2"
                android:layout_height="match_parent">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:src="@drawable/menu_grey_justin2"
                    android:id="@+id/imageView2" />
            </LinearLayout>

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="0dp"
                android:layout_weight="2"
                android:layout_height="match_parent">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:src="@drawable/menu_grey_designers"
                    android:id="@+id/imageView3" />
            </LinearLayout>

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="0dp"
                android:layout_weight="2"
                android:layout_height="match_parent">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:src="@drawable/menu_grey_categories"
                    android:id="@+id/imageView4" />
            </LinearLayout>

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="0dp"
                android:layout_weight="2"
                android:layout_height="match_parent">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:src="@drawable/meny_grey_more2"
                    android:id="@+id/imageView5" />
            </LinearLayout>

        </LinearLayout>
    </android.support.v7.widget.Toolbar>
</RelativeLayout>
+1
source

:

mToolbar = (Toolbar) findViewById(R.id.featured_bottomToolbar);
mToolbar.setContentInsetsAbsolute(0, 0);

Toolbar.

0

:

getSupportActionBar().setDisplayHomeAsUpEnabled(false);
-1
source

Source: https://habr.com/ru/post/1624942/


All Articles