0

I have this layout

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

  <android.support.design.widget.CoordinatorLayout
      android:id="@+id/account_menu_coordinator_layout"
      android:layout_width="match_parent"
      android:layout_height="match_parent">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:text="@string/lores_ipsum"/>

  </android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.DrawerLayout>

and this inflation code:

final View content =
    (View) inflater.inflate(R.layout.activity_account_menu2, coordinatorLayout, false);

which returns this error:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.google.android.libraries.onegoogle.demoapp, PID: 14668
    java.lang.IllegalArgumentException: DrawerLayout must be measured with MeasureSpec.EXACTLY.
        at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1053)

I saw this post

but my layout has match_parent already.

how can it be that i get this exception?

Elad Benda
  • 35,076
  • 87
  • 265
  • 471
  • thats how: https://android.googlesource.com/platform/frameworks/support/+/407e01608ccafe5dc24f82608583f71c34312f9c/v4/java/android/support/v4/widget/DrawerLayout.java#626 – pskink Oct 22 '18 at 15:21
  • read all answer of this : https://stackoverflow.com/questions/31746072/drawerlayout-must-be-measured-with-measurespec-exactly-error – Ali Khaki Oct 22 '18 at 15:24

1 Answers1

0

I had this problem. Try wrapping your DrawerLayout inside a Constraint Layout like thus:

 <androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.drawerlayout.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">
   ....
   </androidx.drawerlayout.widget.DrawerLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Kristy Welsh
  • 7,828
  • 12
  • 64
  • 106