我有一个用于RecyclerView中ViewHolder的XML布局。
这个布局的根元素是一个高度设置为wrap_content
的ConstraintLayout。
在这个扁平的层级结构中,有三个文本视图和一个固定高度的图像视图;可以将其想象为:
<ConstraintLayout>
<TextView height=wrap>
<TextView height=wrap>
<TextView height=wrap>
<ImageView height=150dp>
</ConstraintLayout>
这是一个相对简单的布局。在beta4
中,它在设计师中的显示方式如下(最终在运行时,每个recyclerView单元格都是这样的):
话说回来,这里有以下元素:
三个文本视图(带紫色背景的红色贴带)和高度为150dp的ImageView(灰色部分)。
紫色背景应用于根ConstraintLayout。非常好。
现在看起来是这样的,在Beta 5中没有进行任何修改:
如您所见,紫色(根)约束布局现在“混乱”了,不再像以前一样包裹内容。
我尝试过的事情:
将
app:layout_constraintHeight_default="wrap"
添加到 ConstraintLayout 中(也进行了扩展)。没有任何改变。ImageView 具有一个
app:layout_constraintBottom_toBottomOf="parent"
约束,我尝试删除它,但也没有任何改变。回滚到 beta4 :)
为记录,这是完整的布局(由于某些原因,id 已被重命名,并且没有 tools:text 或类似内容)。布局在其他方面完全相同。
<?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!):)