gpt4 book ai didi

android - ConstaintLayout 内的 DrawerLayout - java.lang.IllegalArgumentException : DrawerLayout must be measured with MeasureSpec. 完全正确

转载 作者:太空狗 更新时间:2023-10-29 15:44:27 25 4
gpt4 key购买 nike

这是我的 xml 布局文件:

<?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 应用程序时,出现错误(在运行时):

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: DrawerLayout must be measured with MeasureSpec.EXACTLY.

所以你必须设置高度和宽度 MeasureSpec.EXACTLY

如果您在代码中使用它。高度和宽度将为 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">

在您的代码中试试这个。

<?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>

关于android - ConstaintLayout 内的 DrawerLayout - java.lang.IllegalArgumentException : DrawerLayout must be measured with MeasureSpec. 完全正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47001482/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com