Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to suppress constraint layout error "MATCH_PARENT is not supported in ConstraintLayout"

On the newest version of constraint layout, Beta 5, using match_parent throws an exception:

android.view.InflateException: Binary XML file line #12: MATCH_PARENT is not supported in ConstraintLayout

As explained in the release note:

"(...) its behavior undefined. To reduce the risk of errors we now throws an exception if we encounter it." - source

They suggested that the correct usage would be to use 0dp (MATCH_CONSTRAINT), but since I have a Drawer Layout inside my constraint layout, setting the width to 0dp throws "DrawerLayout must be measured with MeasureSpec.EXACTLY" error.

So my question is how can I suppress the error "MATCH_PARENT is not supported in ConstraintLayout"?

like image 557
Marcola Carr Avatar asked Feb 11 '17 00:02

Marcola Carr


2 Answers

The replacement of

android:layout_width="match_parent"

in a ConstraintLayout can be done with

android:layout_width="0dp" 
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"

i.e. constraining the widget to the right and left edges of the parent

like image 185
Renaud Tarnec Avatar answered Oct 26 '22 23:10

Renaud Tarnec


At least as of version 1.1.0-beta3 of the constraint layout,

You can use match_parent without issues.

However it's still recommended that you use:

android:layout_width="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
like image 26
Marcola Carr Avatar answered Oct 26 '22 23:10

Marcola Carr