DrawerLayout must be measured with MeasureSpec.EXACTLY. at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:994)

喜夏-厌秋 提交于 2019-12-08 04:15:57

问题


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)


回答1:


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


来源:https://stackoverflow.com/questions/48135040/drawerlayout-must-be-measured-with-measurespec-exactly-at-android-support-v4-wi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!