1

Here is the my mainlayout file .

This is the main layout file where I write the code related to navigation drawer,also include the toolbar by using include.

    <LinearLayout android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:android="http://schemas.android.com/apk/res/android">
        <android.support.v4.widget.DrawerLayout
            android:id="@+id/navigation_Drawerlayout"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            tools:openDrawer="start">
            <include layout="@layout/navigation_drawerlayout" />

            <android.support.design.widget.NavigationView
                android:id="@+id/navigation_View"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="start"
                android:fitsSystemWindows="true">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

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

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/navigationRecycleView"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"></android.support.v7.widget.RecyclerView>
                </LinearLayout>


            </android.support.design.widget.NavigationView>


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










    </LinearLayout>

navigation_toolbarlayout.xml This layout define the toolbar code which one used in above code

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/colorPrimary"
                android:minHeight="?attr/actionBarSize"
                app:titleTextColor="@android:color/white">

                <!-- Screen title -->
                <TextView
                    android:id="@+id/toolbarTitle"
                    style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:text=""
                    android:textColor="@android:color/white"></TextView>
            </android.support.v7.widget.Toolbar>
        </android.support.design.widget.AppBarLayout>
    </android.support.design.widget.CoordinatorLayout>

Logcat

this is error log which is occur in my app.this logcat error will help you to findout what is the main problem

java.lang.IllegalArgumentException: DrawerLayout must be measured with MeasureSpec.EXACTLY. at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:994) at android.view.View.measure(View.java:18809) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5954) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465) at android.widget.LinearLayout.measureVertical(LinearLayout.java:748) at android.widget.LinearLayout.onMeasure(LinearLayout.java:630) at android.view.View.measure(View.java:18809) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5954) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465) at android.widget.LinearLayout.measureVertical(LinearLayout.java:748) at android.widget.LinearLayout.onMeasure(LinearLayout.java:630) at android.view.View.measure(View.java:18809) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5954)

KeLiuyue
  • 8,149
  • 4
  • 25
  • 42
Sumit Kumawat
  • 41
  • 1
  • 7

1 Answers1

5

According to your problem

java.lang.IllegalArgumentException: DrawerLayout must be measured with MeasureSpec.EXACTLY

So you should set EXACTLY width to your DrawerLayout .

You can set android:layout_width="match_parent" and try again .

Change

<android.support.v4.widget.DrawerLayout
            android:id="@+id/navigation_Drawerlayout"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            tools:openDrawer="start">
            <include layout="@layout/navigation_drawerlayout" />

to

<android.support.v4.widget.DrawerLayout
            android:id="@+id/navigation_Drawerlayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            tools:openDrawer="start">
            <include layout="@layout/navigation_drawerlayout" />
KeLiuyue
  • 8,149
  • 4
  • 25
  • 42
  • Could you try it? – KeLiuyue Jan 07 '18 at 10:05
  • 1
    Ever come across the error when it is already `match_parent`? I arrived here with that issue. – Abandoned Cart Nov 04 '18 at 20:35
  • And you can check your root layout in your `xml` . if it used `wrap_content` ,you can change it and try again . @AbandonedCart – KeLiuyue Nov 06 '18 at 09:13
  • @KeLiuyue "it is already `match_parent`" but I was curious if you had any better suggestions than blindly changing `wrap_content` to `match_parent`. The solution was to define dimensions for the window via `getWindow().setLayout` to be passed down to any implied instance of relative dimensions. – Abandoned Cart Nov 06 '18 at 22:33
  • @AbandonedCart you can try use `getWindow().setAttributes(p);` . – KeLiuyue Nov 07 '18 at 01:30
  • @KeLiuyue Please take the time to read my comment, since it provides a much shorter form of the accessor you are trying to suggest. It also states that the issue was **solved** – Abandoned Cart Nov 08 '18 at 03:36