首页 > 解决方案 > 最好的 LinearLayout、RelativeLayout 和最新的 ConstraintLayout

问题描述

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

一些问题:

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

标签: androidandroid-layoutandroid-linearlayoutandroid-relativelayout

解决方案


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

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

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

ConstraintLayout处理比 doLinearLayout和更多的场景RelativeLayoutConstraintLayoutIDE 比 is 更容易通过拖放支持RelativeLayout

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

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

  • 圆形定位

  • 自身的最小和最大尺寸ConstraintLayout(帮助wrap_content避免变得太小或太大)

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

  • 实现一些种类的链

  • 将儿童锚定到基于规则的人工线路,例如GuidelineBarrier


推荐阅读