ConstraintLayout 1.1.0与1.0.2不同,是不是一个bug?

Kon*_*gDa 5 android android-layout android-constraintlayout

如果我使用1.0.2,则3个图像的宽度是平均值,并且它们的高度由我设置的无线电计算.如果我使用1.1.0,它们的高度是0dp,我看不到任何东西,除非我设置
android:layout_height="match_parent"
在根目录中ConstraintLayout.

这是一个错误吗?这是我的代码:

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/iv0"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="#FF0000"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@+id/iv1"
        app:layout_constraintDimensionRatio="2:1"/>

    <ImageView
        android:id="@+id/iv1"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="#00FF00"
        app:layout_constraintDimensionRatio="2:1"
        app:layout_constraintLeft_toRightOf="@id/iv0"
        app:layout_constraintRight_toLeftOf="@+id/iv2"/>

    <ImageView
        android:id="@+id/iv2"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="#0000FF"
        app:layout_constraintDimensionRatio="2:1"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintLeft_toRightOf="@id/iv1"/>

</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

qtm*_*fld 4

根据更新的文档, ConstraintLayout 1.1.0中的布局行为已更改

\n\n
\n

WRAP_CONTENT:强制约束(在 1.1 中添加)
\n 如果维度设置为WRAP_CONTENT,在 1.1 之前的版本中,它们将被视为文字维度 - 这意味着约束不会限制结果维度。虽然一般来说这已经足够了(而且更快),但在某些情况下,您可能想要使用WRAP_CONTENT,但仍要继续强制执行约束来限制结果维度。在这种情况下,您可以添加相应的属性之一:

\n\n
    \n
  • app:layout_constrainedWidth=\xe2\x80\x9dtrue|false\xe2\x80\x9d
  • \n
  • app:layout_constrainedHeight=\xe2\x80\x9dtrue|false\xe2\x80\x9d
  • \n
\n
\n\n

因此,在新版本中,XML 中的这一行生效:

\n\n
android:layout_height="0dp"\n
Run Code Online (Sandbox Code Playgroud)\n\n

您可以通过以下方式解决问题:

\n\n
android:layout_height="0dp"\napp:layout_constrainedHeight="true"\n
Run Code Online (Sandbox Code Playgroud)\n\n

正如这个答案中所写的。

\n\n
\n\n

更新:

\n\n

我误解了这个问题。正如KongDa评论的那样,问题并未得到解决:

\n\n
app:layout_constrainedHeight="true"\n
Run Code Online (Sandbox Code Playgroud)\n\n

该问题已通过以下方式解决:

\n\n
app:layout_constraintWidth_percent="0.333" \n
Run Code Online (Sandbox Code Playgroud)\n\n

在一个最小的示例应用程序中,我检查了其行为,如下所示。

\n\n

步骤1:ConstraintLayout 1.0.2

\n\n

高度不为零。

\n\n

在此输入图像描述

\n\n

步骤2:ConstraintLayout 1.1.0

\n\n

高度变为零。

\n\n

在此输入图像描述

\n\n

步骤3:ConstraintLayout 1.1.0

\n\n

问题已解决app:layout_constraintWidth_percent="0.333"

\n\n

在此输入图像描述

\n\n

因此,布局 XML 为:

\n\n
<?xml version="1.0" encoding="utf-8"?>\n<android.support.constraint.ConstraintLayout\n    xmlns:android="http://schemas.android.com/apk/res/android"\n    xmlns:app="http://schemas.android.com/apk/res-auto"\n    android:layout_width="match_parent"\n    android:layout_height="wrap_content">\n\n    <ImageView\n        android:id="@+id/iv0"\n        android:layout_width="0dp"\n        android:layout_height="0dp"\n        android:background="#FF0000"\n        app:layout_constraintDimensionRatio="2:1"\n        app:layout_constraintLeft_toLeftOf="parent"\n        app:layout_constraintRight_toLeftOf="@+id/iv1"\n        app:layout_constraintWidth_percent="0.333" />\n\n    <ImageView\n        android:id="@+id/iv1"\n        android:layout_width="0dp"\n        android:layout_height="0dp"\n        android:background="#00FF00"\n        app:layout_constraintDimensionRatio="2:1"\n        app:layout_constraintLeft_toRightOf="@id/iv0"\n        app:layout_constraintRight_toLeftOf="@+id/iv2"\n        app:layout_constraintWidth_percent="0.333" />\n\n    <ImageView\n        android:id="@+id/iv2"\n        android:layout_width="0dp"\n        android:layout_height="0dp"\n        android:background="#0000FF"\n        app:layout_constraintDimensionRatio="2:1"\n        app:layout_constraintLeft_toRightOf="@id/iv1"\n        app:layout_constraintRight_toRightOf="parent"\n        app:layout_constraintWidth_percent="0.333" />\n\n</android.support.constraint.ConstraintLayout>\n
Run Code Online (Sandbox Code Playgroud)\n