Android Studio布局编辑器ConstraintLayout:pack vs chain

时间:2017-10-09 05:43:46

标签: android android-studio android-constraintlayout graphical-layout-editor

在Android Studio布局编辑器中,我看到了关于ConstraintLayout的单词“pack”和“chain”。我知道它们都与多个视图在一条线上相互连接有关,但它们的区别对我来说并不清楚。

enter image description here

enter image description here

enter image description here

“pack”和“chain”有什么区别?

1 个答案:

答案 0 :(得分:12)

简短回答

是一组以垂直或水平线绑定在一起的视图。 打包表示视图应保持非常紧密,即相互接触(不包括任何填充)。

Pack表示视图紧密排列在一起。想象一下,在旅行之前,你将衣服紧紧地放在行李箱里。

enter image description here

注意事项:

  • 您可以水平或垂直打包视图。
  • 包装本身并不会将视图限制在彼此之间。

    • 如果它们尚未链接,则打包在布局编辑器中移动它们的绝对位置,使它们彼此相邻。 enter image description here
    • 如果它们被链接,那么将链模式设置为packed会将它们紧密地绑定在一起。

      app:layout_constraintHorizontal_chainStyle="packed"
      

      enter image description here

当两个相邻视图彼此具有约束时发生链。想象一下铁链。

enter image description here

documentation很好地展示了这一点。

enter image description here

该链可以在链中的每个链接(视图)都与其邻居建立双向链接的情况下继续。

enter image description here

连锁模式/风格

正如我上面简要提到的,链条有不同的模式或样式。它们显示在(来自docs的图像)下面。

  1. 传播(默认)
  2. 传播
  3. 加权
  4. 盒装
  5. enter image description here

    所有这些链接。只有底部的打包