Android Studio 布局编辑器 ConstraintLayout:打包 vs 链 [英] Android Studio Layout Editor ConstraintLayout: pack vs chain

查看:38
本文介绍了Android Studio 布局编辑器 ConstraintLayout:打包 vs 链的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Android Studio 布局编辑器中,我看到与 ConstraintLayout 相关的词pack"和chain".我知道它们都与在一条线上相互连接的多个视图有关,但我不清楚它们的区别.

包"和链"有什么区别?

解决方案

简短回答

是一组以垂直或水平线绑定在一起的视图.Pack 意味着视图应该非常紧密地保持在一起,即相互接触(不包括任何填充).

打包

Pack 意味着视图被紧密地打包在一起.想象一下,在旅行之前,您正将衣服紧紧地打包在行李箱中.

注意事项:

  • 您可以水平或垂直打包视图.
  • 包装本身并不限制彼此的视图.

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

      app:layout_constraintHorizo​​ntal_chainStyle="packed"

当两个相邻的视图都相互有约束时,就会出现一个链.想象一下铁链.

这条链可以继续下去,其中链中的每个链接(视图)都有一个到其邻居的双向链接.

连锁模式/风格

正如我上面简要提到的,链有不同的模式或样式.它们如下所示(图片来自

所有这些都链接.只有底部的一个是打包.

In the Android Studio Layout Editor I see the words "pack" and "chain" with respect to a ConstraintLayout. I know they both have something to do with multiple views being connected to each other in a line, but their difference is not clear to me.

What is the difference between "pack" and "chain"?

解决方案

Short answer

A Chain is a group of views that are bound together in a vertical or horizontal line. Pack means that the views should be kept very closely together, ie, touch each other (excluding any padding).

Pack

Pack means that the views are packed tightly together. Imagine that you are packing your clothes tightly together in a suitcase before going on a trip.

Points to note:

  • You can pack views horizontally or vertically.
  • Packing doesn't in itself doesn't constrain the views to each other.

    • If they are not already chained, then packing moves their absolute position in the Layout Editor so that they are adjacent to each other.
    • If they are chained, then setting the Chain mode to packed binds them closely together.

      app:layout_constraintHorizontal_chainStyle="packed"
      

Chain

A chain occurs when two adjacent views both have constraints to each other. Imagine an iron link chain.

The documentation shows this well.

This chain can continue where every link (view) in the chain has a two-way link to its neighbors.

Chain mode/style

As I briefly mentioned above, there are different modes or styles for a chain. They are shown below (image from docs).

  1. Spread (default)
  2. Spread inside
  3. Weighted
  4. Packed

All of these are chained. Only the bottom one is packed.

这篇关于Android Studio 布局编辑器 ConstraintLayout:打包 vs 链的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆