4

我在RecyclerView内部有一个ViewHolder的XML布局。ConstraintLayout beta5 wrap_content未正确包装

此布局的根部是一个ConstraintLayout,其高度设置为wrap_content

在这个平面层次结构中,有3个textview和一个固定高度的图像视图;认为:

<ConstraintLayout> 
    <TextView height=wrap> 
    <TextView height=wrap> 
    <TextView height=wrap> 
    <ImageView height=150dp> 
</ConstraintLayout> 

这是一个相对简单的布局。在beta4这是它的外观在设计(并最终在运行时,每个recyclerView细胞):

Beta4

道歉的“繁文缛节”,但它的保密协议等等等等。

如此说来,所述元素是:

3个文本视图(红色胶粘用一个漂亮的紫色背景) 与150dp高度的ImageView的是灰色的事情。

紫色背景已应用于根ConstraintLayout。一切都很好。

现在,这是它的外观,没有一个单一的修改与测试版5:

beta5

正如你可以看到紫色(根)约束布局现在“糊涂”,不包内容像以前一样。

事情我想:

  1. 添加app:layout_constraintHeight_default="wrap"到ConstraintLayout(和传播太)。没有区别。

  2. 该ImageView有一个app:layout_constraintBottom_toBottomOf="parent"约束,我试图删除,也没有任何区别。

  3. 恢复到BETA4 :)

根据记录,这是完整的布局(ID的已更名为繁文缛节的原因,并没有工具:文字或类似,由于同样的原因) 。布局完全一样。

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/colorAccent"> 

    <TextView 
     android:id="@+id/toplabel" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginStart="8dp" 
     android:layout_marginTop="8dp" 
     android:text="" 
     android:textStyle="bold" 
     app:layout_constraintBottom_toBottomOf="@+id/top_bottom_label" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toLeftOf="@+id/top_right_label" 
     app:layout_constraintTop_toTopOf="parent" /> 

    <TextView 
     android:id="@+id/top_right_label" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginEnd="8dp" 
     android:layout_marginTop="8dp" 
     android:ellipsize="end" 
     android:gravity="end" 
     android:maxLines="1" 
     android:text="" 
     app:layout_constraintBottom_toTopOf="@+id/top_bottom_label" 
     app:layout_constraintHorizontal_bias="1.0" 
     app:layout_constraintLeft_toRightOf="@+id/toplabel" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintVertical_chainStyle="packed" /> 

    <TextView 
     android:id="@+id/top_bottom_label" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginEnd="8dp" 
     android:layout_marginTop="8dp" 
     android:ellipsize="end" 
     android:gravity="end" 
     android:maxLines="1" 
     android:text="" 
     app:layout_constraintHorizontal_bias="1.0" 
     app:layout_constraintLeft_toRightOf="@+id/toplabel" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/top_right_label" /> 

    <ImageView 
     android:id="@+id/imageview" 
     android:layout_width="0dp" 
     android:layout_height="150dp" 
     android:layout_marginTop="8dp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/top_bottom_label" 
     app:srcCompat="@android:color/darker_gray" /> 

</android.support.constraint.ConstraintLayout> 

我应该做些什么不同吗? (我知道我可以用一个RelativeLayout的替代这一点,可能会做同样的,但无论如何...我相信ConstraintLayout!):)

回答

5

filed a bug这件事,我有一种变通方法。

这是一个回归,将是固定的(我们希望),但......原来我的链也是错误的定义。我top_bottom_label没有底部端点,并根据链的文件内容应在两个端点连接。

所以我加app:layout_constraintBottom_toTopOf="@id/imageview"top_bottom_label这似乎适用于我的情况。我有,有效地将imageView添加到链中,即使我真的不太在乎它。它现在工作。

更新2017年2月14日:ConstraintLayout team @ Google在master中修复了这个问题。它可能会在下一个版本中修复。 (谢谢!)。