【问题标题】:Best of LinearLayout, RelativeLayout and of latest ConstraintLayout最好的 LinearLayout、RelativeLayout 和最新的 ConstraintLayout
【发布时间】:2018-05-05 18:32:06
【问题描述】:

我对此有很多疑问。我很擅长使用 LinearLayout、RelativeLayout 或 ConstraintLayout,想知道最好的。 如果某些人有理由使用其中之一。

一些问题:

  1. 我认为LinearLayout 会添加一个节点层次结构,这将比RelativeLayout 或ContraintLayout 花费更多的时间来渲染,对吗?
  2. 为什么android考虑ContraintLayoutRelativeLayoutLinearLayout使用更多?即使我可以在LinearLayoutRelativeLayout 中进行相同的布局

【问题讨论】:

  • 你读过this的文章吗?
  • 直到,这很好理解。在这些布局中,您认为这是我的最佳答案吗?
  • 我相信是这样,它也解释了android如何测量布局和税收系统。一般来说,ConstraintLayout 提供了更大的灵活性,并且有助于在不影响性能的情况下构建布局。
  • 感谢您的链接,我在下面得到了预期的答案。

标签: android android-layout android-linearlayout android-relativelayout


【解决方案1】:

我认为 LinearLayout 会添加一个节点层次结构,这将比 RelativeLayout 或 ContraintLayout 花费更多时间来渲染,对吗?

嵌套LinearLayout 小部件可能渲染速度较慢。不能保证它渲染得更慢。使用嵌套权重是获取一组慢速嵌套LinearLayout 小部件的一种已知方法。

为什么 android 考虑使用 ContraintLayout 而不是使用 RelativeLayout 和 LinearLayout?

ConstraintLayoutLinearLayoutRelativeLayout 处理更多的场景。 ConstraintLayoutRelativeLayout 更容易让 IDE 通过拖放来支持。

即使我可以在 LinearLayout 或 RelativeLayout 中进行相同的布局

LinearLayoutRelativeLayout 中有多种场景难以实现,但ConstraintLayout 可以轻松处理,例如:

  • 圆形定位

  • ConstraintLayout 本身的最小和最大尺寸(帮助wrap_content 变得过小或过大)

  • 让孩子保持特定的纵横比

  • 实现一些种类的链

  • 将孩子锚定到基于规则的人工行中,例如 GuidelineBarrier

【讨论】:

  • 我怀疑 Google 添加了 ConstraintLayout 是为了让 iOS 开发者更容易地跨界到 Android UI 设计。
  • @Barns:这很有可能,虽然因为我很少做 iOS 开发,所以我无法对此发表评论。
猜你喜欢
  • 1970-01-01
  • 2021-08-01
  • 2018-04-29
  • 2016-09-16
  • 2020-04-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多