possible bug: DrawerLayout must be measured with MeasureSpec.EXACTLY when using ConstraintLayout

See original GitHub issue

About this issue

trying to put drawer under the toolbar as explained here and getting DrawerLayout must be measured with MeasureSpec.EXACTLY exception.

after some playing around with it i have noticed it’s only happening if my XML root view is ConstraintLayout. if i change it to RelativeLayout, it working fine.

NOT working (getting exception mentioned above):

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.Toolbar
        <!--some values-->
     />

    <FrameLayout
        android:id="@+id/drawerContainer"
               <!--some values-->
     >

        <ScrollView
           <!--some values-->
     >
            <!--layout content-->

        </ScrollView>
    </FrameLayout>
</android.support.constraint.ConstraintLayout>

working:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.Toolbar
        <!--some values-->
     />

    <FrameLayout
        android:id="@+id/drawerContainer"
               <!--some values-->
     >

        <ScrollView
           <!--some values-->
     >
            <!--layout content-->

        </ScrollView>
    </FrameLayout>
</RelativeLayout>

Details

  • [ ] Used library version 6.0.9
  • [ ] Used support library version 27.1.1
  • [ ] Used gradle build tools version 3.1.3
  • [ ] Used tooling / Android Studio version 3.1.3
  • [ ] Other used libraries, potential conflicting libraries using the kotlin wrapper library

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mikepenzcommented, Sep 16, 2018

Ok so this is a known thing of the DrawerLayout and the ConstraintLayout and many people complain about it…

https://stackoverflow.com/questions/42170694/how-to-suppress-constraint-layout-error-match-parent-is-not-supported-in-constr https://stackoverflow.com/questions/47001482/drawerlayout-inside-constaintlayout-java-lang-illegalargumentexception-drawer

I was able though to figure out a configuration of the layout with the ConstraintLayout which works perfectly 😃

See this commit: https://github.com/mikepenz/MaterialDrawer/blob/3878084e7a0e37631ac85694c3ccfb0cb85afff3/app/src/main/res/layout/activity_sample_custom_container_dark_toolbar.xml

And specifically these lines (super important those 0dp) https://github.com/mikepenz/MaterialDrawer/blob/3878084e7a0e37631ac85694c3ccfb0cb85afff3/app/src/main/res/layout/activity_sample_custom_container_dark_toolbar.xml#L23-L28

using this will make it work perfectly fine 😉 the sample now also uses constraint layouts instead of relative layouts 😄

0reactions
atulbhardwaj0900commented, May 19, 2020

Ok so this is a known thing of the DrawerLayout and the ConstraintLayout and many people complain about it…

https://stackoverflow.com/questions/42170694/how-to-suppress-constraint-layout-error-match-parent-is-not-supported-in-constr https://stackoverflow.com/questions/47001482/drawerlayout-inside-constaintlayout-java-lang-illegalargumentexception-drawer

I was able though to figure out a configuration of the layout with the ConstraintLayout which works perfectly 😃

See this commit: https://github.com/mikepenz/MaterialDrawer/blob/3878084e7a0e37631ac85694c3ccfb0cb85afff3/app/src/main/res/layout/activity_sample_custom_container_dark_toolbar.xml

And specifically these lines (super important those 0dp) https://github.com/mikepenz/MaterialDrawer/blob/3878084e7a0e37631ac85694c3ccfb0cb85afff3/app/src/main/res/layout/activity_sample_custom_container_dark_toolbar.xml#L23-L28

using this will make it work perfectly fine 😉 the sample now also uses constraint layouts instead of relative layouts 😄

This is working

Read more comments on GitHub >

github_iconTop Results From Across the Web

DrawerLayout must be measured with MeasureSpec ...
using Android Studio and got the runtime error: java.lang.IllegalArgumentException: DrawerLayout must be measured with MeasureSpec.EXACTLY. – Ismail Rubad. Jul ...
Read more >
Android : DrawerLayout must be measured with MeasureSpec ...
Android : DrawerLayout must be measured with MeasureSpec. EXACTLY error [ Beautify Your Computer : https://www.hows.tech/p/recommended.html ] ...
Read more >
ViewGroup - Android Developers
Use a custom view or layout to handle this functionality instead ... of this view to measure itself, taking into account both the...
Read more >
Source Code for ConstraintLayout.java - AndroidX Tech
<h6>Percent dimension</h6> * To use percent, you need to set the following: * <ul> ... EXACTLY); } child.measure(horizontalSpec, verticalSpec); widget.
Read more >
constraintlayout/src/main/java/android/support/constraint ...
A {@code ConstraintLayout} is a {@link android.view.ViewGroup} which allows you ... There are currently various types of constraints that you can use:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found