Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the Toolbar able to work in RelativeLayout?

I'm new in Android Programming. I would like to ask that does Toolbar able to work in RelativeLayout? So far I manage to create them using LinearLayout. Would like to hear some guidance form you all. Thanks.

The question is: how do I prevent the content from overlaying on top of the Toolbar content?

like image 390
DanKCl Avatar asked Nov 24 '14 11:11

DanKCl


1 Answers

Yes, we can add toolbar within Relative layout .

But you need to mention layout:below attribute since it will overlap.

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        android:background="#ffbb00">


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

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/toolbar"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="49dp"
        android:src="@drawable/ic_launcher" />

</RelativeLayout>
like image 137
kunal.c Avatar answered Sep 28 '22 08:09

kunal.c