Toolbar is behind Layouts

3

Hello, I'm developing a home screen, and it has 1 toolbar and 2 linearLayouts dividing the screen into 2. the problem is that the toolbar is behind the layouts and does not appear when it executes. how do I bring the toolbar to the forefront over the linearlayout?

<?xmlversion="1.0" encoding="utf-8"?>

<android.support.v7.widget.Toolbar
    android:id="@+id/tb_main"
    android:layout_height="?attr/actionBarSize"
    android:layout_width="match_parent"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:layout_alignParentLeft="true"
    android:layout_margin="8dp"
    android:elevation="4dp"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerVertical="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true">

    <LinearLayout
        android:layout_weight="0.5"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"></LinearLayout>
    <LinearLayout
        android:layout_weight="0.5"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"></LinearLayout>
</LinearLayout>

    
asked by anonymous 25.11.2015 / 21:49

2 answers

0

Simply put your toolbar last in the layout

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerVertical="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true">

    <LinearLayout
        android:layout_weight="0.5"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"></LinearLayout>
    <LinearLayout
        android:layout_weight="0.5"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"></LinearLayout>
</LinearLayout>

<android.support.v7.widget.Toolbar
    android:id="@+id/tb_main"
    android:layout_height="?attr/actionBarSize"
    android:layout_width="match_parent"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:layout_alignParentLeft="true"
    android:layout_margin="8dp"
    android:elevation="4dp"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
    
25.11.2015 / 21:52
0

By the attributes of your LinearLayout container, the parent of these views is a RelativeLayout, correct?!

RelativeLayout works differently than other views. You need to inform the hierarchy of views, so just put the android: layout_below="@ + id / tb_main" attribute in your LinearLayout container, stating that it should be below the toolbar.

<LinearLayout
    android:layout_below="@+id/tb_main"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerVertical="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true">
    
26.11.2015 / 02:09