Toolbar is behind the Layouts

Asked

Viewed 81 times

3

Hello, I am developing a home screen, and has 1 Toolbar and 2 linearLayouts dividing the screen into 2. The problem is that Toolbar is "behind" the layouts and does not appear when it runs. how I bring Toolbar to the foreground on top of the linearlayout?

inserir a descrição da imagem aqui

<?xml version="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>

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"/>

0

By the attributes of your Linearlayout container, the parent of these views is a Relativelayout, correct?!

Relativelayout works different from other views. You need to inform the hierarchy of views, so just put the attribute in your container Linearlayout android:layout_below="@+id/tb_main", stating that it should be below 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">

Browser other questions tagged

You are not signed in. Login or sign up in order to post.