Jitender February 2016

Toolbar takes full screen in Android Navigation Drawer

I made a toolbar:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="80dp"
    android:background="#FF5722"
    >
</android.support.v7.widget.Toolbar>

The problem is when I include this in my main_activity.xml like below:

<android.support.v4.widget.DrawerLayout

    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/DrawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:elevation="7dp">


<!--<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <span style="font-size: x-small;"><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    tools:context=".MainActivity">-->

    <include
        android:id="@+id/tool_bar"
        layout="@layout/tool_bar"
        android:layout_height="80dp"
        android:layout_width="match_parent"
        />



        <android.support.v7.widget.RecyclerView
            android:id="@+id/RecyclerView"
            android:layout_width="320dp"
            android:layout_height="match_parent"
            android:layout_gravity="left"
            android:background="#ffffff"
            android:scrollbars="vertical">
        &l        

Answers


A.R. February 2016

Your main_activity layout should look like this:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/DrawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:elevation="7dp">

    // your first view containing tool bar and framelayout
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <include layout="@layout/tool_bar"></include>

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </FrameLayout>

    </LinearLayout>

    // your second view i.e. receylerview
    <android.support.v7.widget.RecyclerView
        android:id="@+id/RecyclerView"
        android:layout_width="320dp"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:background="#ffffff"
        android:scrollbars="vertical">
    </android.support.v7.widget.RecyclerView>

</android.support.v4.widget.DrawerLayout>

Post Status

Asked in February 2016
Viewed 3,044 times
Voted 4
Answered 1 times

Search




Leave an answer