1.百分比尺寸
宽度为 0dp(或 match_constraint)的小部件的默认行为是展开的(可通过 layout_constraintWidth_default 属性进行配置)。在 ConstraintLayout 1.0.x 中,我们可以选择将其更改为 wrap,而在 1.1.x 中,我们有一个新值 percent,允许我们将小部件设置为占用可用空间的某个百分比。
<!-- the widget will take 40% of the available space -->
app:layout_constraintWidth_default="percent"
app:layout_constraintWidth_percent="0.4"
2。障碍
在这个新的小部件中,我们有一些来自 ConstraintLayout.com 的示例。障碍将避免一个或多个小部件绕过障碍。发生这种情况时,屏障将自行移动,并避免将小部件放置在其上方。
在下面的示例中,text1 和 text2 的 end 属性都不能绕过障碍。发生这种情况时,Barrier 将向右移动(或向左移动,如果在 RTL 布局中)。这在处理不同的小部件尺寸时尤其少见,具体取决于某些配置或国际化。
<android.support.constraint.ConstraintLayout...>
<TextView
android:id="@+id/text1" ... />
<TextView
android:id="@+id/text2" ... />
<android.support.constraint.Barrier
android:id="@+id/barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="end" <!-- start, top, bottom, right... -->
app:constraint_referenced_ids="text1,text2" />
<TextView
android:id="@+id/text3"
...
app:layout_constraintStart_toEndOf="@+id/barrier" />
</android.support.constraint.ConstraintLayout>
3.群组
组,就像指南一样,是大小为 0 的小部件。但组有助于将一些操作应用于一组小部件。最常见的情况是控制小部件集合的可见性。在处理这种情况时,最常见的解决方案是在 Activity 或 Fragment 内部维护一个列表或一组视图,甚至添加一个 ViewGroup 并将所有视图放入其中,控制容器的可见性。现在,您只需要将它们的 id 添加到 Group 中,group 就会将操作传播到所有插入的视图。
<android.support.constraint.ConstraintLayout ...>
<TextView
android:id="@+id/text1" ... />
<TextView
android:id="@+id/text2" ... />
<android.support.constraint.Group
android:id="@+id/group"
...
app:constraint_referenced_ids="text1,text2" />
</android.support.constraint.ConstraintLayout>
在这种情况下,如果我们调用
group.setVisibility(View.GONE);
那么 text1 和 text2 将收到 GONE 可见性。
原text here。
description here.的官方文档