自从切换到 ConstraintLayout 版本 1.1.0-beta4 以来,我的几个布局都崩溃了。在进行任何更改之前,我想更好地了解利润率如何运作ConstraintLayout
链。下面我比较一下布局ConstraintLayout
版本1.0.2到版本1.1.0-beta4,但我相信这个问题首先出现在1.1.0-beta2中。
我的目标是让一些文本视图在屏幕上延伸,并在第一个和第二个文本视图以及第二个和第三个文本视图之间留有间隙。背景应显示在这些边距中。为此,我创建一条水平链,并指定从左侧文本视图到中心文本视图的结束边距以及从中心文本视图到右侧文本视图的结束边距。水平链条样式是spread_inside
.
示例 1 - 使用 ConstraintLayout 版本 1.0.2
这就是 1.0.2 版本中的情况,也是我所期望的。
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@android:color/holo_blue_light">
<TextView
android:id="@+id/tvLeft"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_marginEnd="8dp"
android:background="@android:color/white"
android:gravity="center"
android:text="Text1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/tvCenter"
app:layout_constraintHorizontal_chainStyle="spread_inside"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/tvCenter"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_marginEnd="8dp"
android:background="@android:color/white"
android:gravity="center"
android:text="Text2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/tvRight"
app:layout_constraintStart_toEndOf="@+id/tvLeft"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/tvRight"
android:layout_width="0dp"
android:layout_height="35dp"
android:background="@android:color/white"
android:gravity="center"
android:text="Text3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/tvCenter"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="HardcodedText" />
</android.support.constraint.ConstraintLayout>
示例 2 - 使用 ConstraintLayout 版本 1.1.0-beta4
在 1.1.0-beta4 版本中,相同的布局如下所示ConstraintLayout
。请注意,边距已消失。我希望这看起来应该与示例 1 相同,但事实并非如此。
示例 3 - 使用带有起始边距的 ConstraintLayout 版本 1.1.0-beta4
如果我采用相同的布局并简单地添加起始边距8dp
到右侧的文本视图(tvRight
),我的边距不仅重新出现在中心和右侧文本视图之间,而且还出现在左侧和中心文本视图之间,尽管我没有更改那里的边距。
这不仅仅是之前设定的利润突然得到兑现。如果我将最右侧文本视图的起始边距设置为“48dp”,那么看起来是48dp
边距也出现在左侧和中心文本视图之间。
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@android:color/holo_blue_light">
<!-- TextViews tvLeft & tvRight not shown but are the same as above.-->
<TextView
android:id="@+id/tvRight"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_marginStart="48dp"
android:background="@android:color/white"
android:gravity="center"
android:text="Text3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/tvCenter"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="HardcodedText" />
</android.support.constraint.ConstraintLayout>
所以,我的问题是,“为什么我会看到这些结果?”边距是如何处理的ConstraintLayout
链条,特别是spread_inside
链子?连锁利润的处理方式是否发生了变化,或者我错过了什么?我正在寻找解释或参考一些解释这一切的文档。