android.view.InflateException:二进制 XML 文件第 XX 行:二进制 XML 文件第 XX 行:膨胀类 androidx.constraintlayout.widget.ConstraintLayout 时出错。原因:java.lang.IllegalArgumentException:给定的输出必须是与输入不同的布局。不支持并行约束。
android.view.InflateException: Binary XML file line #XX: Binary XML file line #XX: Error inflating class androidx.constraintlayout.widget.ConstraintLayout. Cause: java.lang.IllegalArgumentException: The given output must be a different layout from the input. Parallel constraints not supported.
ID: android/layout-inflate-constraintlayout-parallel-constraint
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| ConstraintLayout 2.1.4 | active | — | — | — |
| ConstraintLayout 2.2.0 | active | — | — | — |
| AndroidX 1.6.0 | active | — | — | — |
根因分析
ConstraintLayout XML 包含冲突或并行的约束(例如,同一视图上同时使用 `layout_constraintLeft_toLeftOf` 和 `layout_constraintRight_toRightOf`,而没有正确的链或偏差),导致布局解析器在膨胀时无法解决。
English
ConstraintLayout XML contains conflicting or parallel constraints (e.g., both `layout_constraintLeft_toLeftOf` and `layout_constraintRight_toRightOf` on the same view without proper chain or bias) that the layout parser cannot resolve during inflation.
官方文档
https://developer.android.com/reference/androidx/constraintlayout/widget/ConstraintLayout解决方案
-
In your XML layout, identify the view causing the error and remove one of the parallel constraints. For example, if a TextView has both `app:layout_constraintLeft_toLeftOf="parent"` and `app:layout_constraintRight_toRightOf="parent"`, replace them with `app:layout_constraintStart_toStartOf="parent"` and `app:layout_constraintEnd_toEndOf="parent"` to create a centered horizontal constraint, or use a chain with `app:layout_constraintHorizontal_chainStyle="packed"`.
-
Wrap the conflicting view in a nested ConstraintLayout or use a different layout container like LinearLayout to avoid parallel constraints entirely.
无效尝试
常见但无效的做法:
-
80% 失败
The Layout Editor often generates parallel constraints automatically when dragging; manual removal without understanding the conflict can reintroduce the same error.
-
85% 失败
The error is a validation issue in the XML, not a library bug; downgrading may hide the symptom but the underlying constraint conflict remains and can cause runtime crashes.