ConstaintLayout中的DrawerLayout-java.lang.IllegalArgumentException:必须使用MeasureSpec.EXACTLY测量DrawerLayout [英] DrawerLayout inside ConstaintLayout - java.lang.IllegalArgumentException: DrawerLayout must be measured with MeasureSpec.EXACTLY

查看:115
本文介绍了ConstaintLayout中的DrawerLayout-java.lang.IllegalArgumentException:必须使用MeasureSpec.EXACTLY测量DrawerLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的xml布局文件:

Here my xml layout file:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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.v4.widget.DrawerLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent">    
    </android.support.v4.widget.DrawerLayout>        

</android.support.constraint.ConstraintLayout>

但是当我启动Android应用程序时,我在运行时遇到错误:

But when I start my Android app I get error (on Runtime):

E/AndroidRuntime: FATAL EXCEPTION: main
 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:15848)
     at android.support.constraint.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:934)

推荐答案

您的问题是

java.lang.IllegalArgumentException:必须使用MeasureSpec.EXACTLY测量DrawerLayout.

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

因此您必须设置高度和宽度MeasureSpec.EXACTLY.

So you must set height and width MeasureSpec.EXACTLY .

如果在代码中使用它,则高度和宽度将为MeasureSpec.EXACTLY.

If you use this in your code .The height and width will be MeasureSpec.EXACTLY .

<android.support.v4.widget.DrawerLayout
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent">

在您的代码中尝试一下.

Try this in your code .

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout     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.v4.widget.DrawerLayout
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent">    
</android.support.v4.widget.DrawerLayout>

</android.support.constraint.ConstraintLayout>

这篇关于ConstaintLayout中的DrawerLayout-java.lang.IllegalArgumentException:必须使用MeasureSpec.EXACTLY测量DrawerLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆