DrawerLayout внутри ConstaintLayout — java.lang.IllegalArgumentException: DrawerLayout необходимо измерять с помощью MeasureSpec.EXACTLY

Вот мой файл макета 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)

person a_subscriber    schedule 29.10.2017    source источник
comment
См. Мой ответ drawerlayout должен быть измерен с помощью Measurespec exac"> stackoverflow.com/questions/32515527/   -  person Shafqat Kamal    schedule 19.12.2017


Ответы (2)


Ваша проблема

java.lang.IllegalArgumentException: DrawerLayout необходимо измерять с помощью 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">

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>
person KeLiuyue    schedule 29.10.2017

Макет ящика должен быть корневым элементом в макете. Вот почему возникает ошибка.

Кроме того, у него должно быть два дочерних элемента: первый — это вид навигации, а второй — макет, который включает ваш контент.

person Valentun    schedule 29.10.2017