3

当我在约束布局中使用android:layout_height="match_parent"orandroid:layout_width="match_parent"作为子项的高度/宽度并构建 Gradle 文件时,它会自动更改为android:layout_height="0dp"or android:layout_widtht="0dp"

从技术上讲, 0dpmatch_parent之间存在巨大差异。

大多数时候它不会影响我的布局,但有时这东西会完全破坏我的约束布局。

我不知道为什么会这样。
请指导我。

4

3 回答 3

7

ConstraintLayout 不支持 match_parent。如果您想要相同的行为,请使用 0dp 并将每一侧的约束设置为父级。

于 2016-10-19T14:48:09.980 回答
3

您不应将 match_parent 用于 ConstraintLayout 中的任何视图。而是使用“匹配约束”(0dp)

match_parent表示filling whats left0dp 的意思match constraints。在 ConstraintLayout 中,match_parent不支持。

match_parent它的位置(x,y 和宽度/高度)依赖于它的父级,但 0dp 可以由约束/位置定义

于 2017-04-25T10:29:10.340 回答
0

与我一起将相对项放在另一个元素下,宽度匹配父项的方法是:

<RelativeLayout
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/xxx"
    app:layout_constraintEnd_toEndOf="@+id/xxx"
    >
于 2017-04-29T05:39:50.083 回答