如何抑制约束布局错误 "MATCH_PARENT is not supported in ConstraintLayout"
How to suppress constraint layout error "MATCH_PARENT is not supported in ConstraintLayout"
在最新版本的约束布局 Beta 5 上,使用 match_parent 会引发异常:
android.view.InflateException: Binary XML file line #12: MATCH_PARENT is not supported in ConstraintLayout
如发行说明中所述:
"(...) its behavior undefined. To reduce the risk of errors we now throws an
exception if we encounter it." - source
他们建议正确的用法是使用 0dp (MATCH_CONSTRAINT),但由于我的约束布局中有一个抽屉布局,将宽度设置为 0dp 会引发 "DrawerLayout must be measured with MeasureSpec.EXACTLY" 错误。
所以我的问题是如何抑制错误 "MATCH_PARENT is not supported in ConstraintLayout"?
替换
android:layout_width="match_parent"
在 ConstraintLayout 中可以用
完成
android:layout_width="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
即将小部件限制在父级的左右边缘
至少从约束布局的 1.1.0-beta3 版开始,
您可以毫无问题地使用 match_parent。
不过还是建议您使用:
android:layout_width="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
在最新版本的约束布局 Beta 5 上,使用 match_parent 会引发异常:
android.view.InflateException: Binary XML file line #12: MATCH_PARENT is not supported in ConstraintLayout
如发行说明中所述:
"(...) its behavior undefined. To reduce the risk of errors we now throws an exception if we encounter it." - source
他们建议正确的用法是使用 0dp (MATCH_CONSTRAINT),但由于我的约束布局中有一个抽屉布局,将宽度设置为 0dp 会引发 "DrawerLayout must be measured with MeasureSpec.EXACTLY" 错误。
所以我的问题是如何抑制错误 "MATCH_PARENT is not supported in ConstraintLayout"?
替换
android:layout_width="match_parent"
在 ConstraintLayout 中可以用
完成android:layout_width="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
即将小部件限制在父级的左右边缘
至少从约束布局的 1.1.0-beta3 版开始,
您可以毫无问题地使用 match_parent。
不过还是建议您使用:
android:layout_width="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"