Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LinearLayout inside a ToolBar is not matching parent

I put a LinearLayout1 in the ToolBar.Then another 5 LinearLayouts in the LinearLayout1. Each child LinearLayout has an ImageView. Here my problem is that the LinearLayout1 is not matching parent width.That I have showed in the image(in red circle). The black color is the background that I have given to 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 output I have got.

enter image description here

like image 348
Thomas M Kurialassery Avatar asked Jan 19 '16 10:01

Thomas M Kurialassery


People also ask

Is LinearLayout deprecated?

This constant was deprecated in API level 28.

Which is better LinearLayout or RelativeLayout?

Relativelayout is more effective than Linearlayout. From here: It is a common misconception that using the basic layout structures leads to the most efficient layouts. However, each widget and layout you add to your application requires initialization, layout, and drawing.

Can we use LinearLayout in ConstraintLayout?

Most of what can be done in LinearLayout and RelativeLayout can now be done with a new layout system called ConstraintLayout. It's important to note the class hierarchy of these View Layouts.


1 Answers

Add the following properties to your Toolbar element.

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

Default value of contentInsetStart is 16dp. You would need to set it to 0.

like image 168
frogatto Avatar answered Sep 17 '22 18:09

frogatto