Search code examples
androidandroid-toolbarandroid-tablayout

remove blank space in toolbar layout


<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/appbar_padding_top"
    android:theme="@style/AppTheme.AppBarOverlay">
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/toolbarheight"
        android:background="@drawable/navigation_bar_top"
        app:popupTheme="@style/AppTheme.PopupOverlay">
        <LinearLayout
            android:layout_width="260dp"
            android:layout_height="match_parent"
            android:orientation="horizontal">
            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/background_toolbar_main" />
        </LinearLayout>
    </android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>

So i got the problem, I got two tabs in the toolbar section, but I don't know why I can't start my tabs from the left side, I got some spacing and got no idea how to remove it.

I tried to set all paddings to "0" or "false" can't find anything

enter image description here


Solution

  • I'm not suggesting to do so but however, the answer to your question is to place both Toolbar & TabLayout inside the LinearLayout like this:

    <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
    
                <android.support.design.widget.TabLayout
                    android:id="@+id/tabs"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="@color/red" />
    
                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="@color/orange" />
            </LinearLayout>
    
    </android.support.design.widget.AppBarLayout>
    

    Output:

    enter image description here