首页 > 解决方案 > 2.0.2版本的约束布局及其尺寸比属性发生了什么变化?

问题描述

我有这样的 ImageView 设置

<ImageView
    android:layout_width="0dp"
    android:layout_height="@dimen/video_file_item_image_height"
    android:background="@color/black"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintDimensionRatio="16:9"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

implementation 'androidx.constraintlayout:constraintlayout:2.0.1'

看起来像这样

在此处输入图像描述

但与

implementation 'androidx.constraintlayout:constraintlayout:2.0.2'

ImageView 不可见

在此处输入图像描述

更新

版本 2.0.3 它仍然没有修复,它只有在你没有设置 dp 的高度时才有效(例如你设置wrap_content了)并且app:layout_constraintEnd_toEndOf=也是必需的,但它的工作方式不同,我需要在 DPI 中设置高度!它在 2.0.1 中像这样工作,app:layout_constraintEnd_toEndOf=不需要设置

标签: androidandroid-constraintlayout

解决方案


看起来这是一个已知问题:https ://issuetracker.google.com/issues/170313444

推荐的解决方法是将其添加到您的ConstraintLayout标签中:

app:layout_optimizationLevel="cache_measures"

推荐阅读