本文介绍了DrawerLayout必须使用MeasureSpec.EXACTLY进行测量.在android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:994)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的mainlayout文件.

这是主要的布局文件,我在其中编写了与导航抽屉相关的代码,还通过使用include包含了工具栏.

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这种布局定义了上面代码中使用的toolbar代码

navigation_toolbarlayout.xmlThis 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

这是我的应用程序中出现的错误日志.此logcat错误将帮助您找出主要问题是什么

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

推荐答案

根据您的问题

因此,您应该将EXACTLY宽度设置为DrawerLayout.

So you should set EXACTLY width to your DrawerLayout .

您可以设置android:layout_width="match_parent"并重试.

更改

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

这篇关于DrawerLayout必须使用MeasureSpec.EXACTLY进行测量.在android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:994)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-07 14:39