最好的 LinearLayout、RelativeLayout 和最新的 ConstraintLayout

Best of LinearLayout, RelativeLayout and of latest ConstraintLayout

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

一些问题:

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

I think LinearLayout will add a hierarchy of nodes which will take more time to render than RelativeLayout or ContraintLayout, is it right?

嵌套的LinearLayout 小部件可以 呈现得更慢。不能保证它 呈现得更慢。使用嵌套权重是获得一组缓慢的嵌套 LinearLayout 小部件的一种已知方法。

Why android is considering ContraintLayout to use more than RelativeLayout and LinearLayout?

ConstraintLayoutLinearLayoutRelativeLayout 处理更多的场景。 ConstraintLayoutRelativeLayout.

更容易通过 drag-and-drop 支持 IDE

Even i can make same layout in LinearLayout or RelativeLayout

有多种情况在LinearLayoutRelativeLayout中难以实现,但ConstraintLayout却可以轻松应对,例如:

  • 循环定位

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

  • child保持特定的宽高比

  • 实现一些链的变体

  • 锚定children到人工rules-based行,例如GuidelineBarrier