单个LinearLayout与单个ConstraintLayout

时间:2018-03-29 10:34:17

标签: android android-constraintlayout

如果我只有一个包含少量项目的LinearLayout,那么用ConstraintLayout替换它会有什么影响

<LinearLayout>
   <TextView>
   <TextView>
   <TextView>
</LinearLayout>

VS

<ConstraintLayout>
   <TextView>
   <TextView>
   <TextView>
</ConstraintLayout>

他们的效率有什么不同吗?

2 个答案:

答案 0 :(得分:3)

对于这样一个没有嵌套且只有3个子TextView的简单布局,LinearLayout在概念复杂性,性能,Android Studio的拖放用户界面,XML行以及应用程序的kB大小方面是最佳的。也许我忘记了一些东西,但是在这种情况下,我不敢浪费时间和其他东西(除了LinearLayout之外)弄乱东西。

答案 1 :(得分:0)

ConstraintLayout被认为比RelativeLayout更好。在SO上看到这个问题的答案:

https://stackoverflow.com/a/37992834/5956451

由于一直认为RelativeLayout比LinearLayout更有效,我们可以得出结论,ConstraintLayout优于LinearLayout。

在其Android开发者博客上,Google详细介绍了ConstraintLayout的性能优势:

https://android-developers.googleblog.com/2017/08/understanding-performance-benefits-of.html

也就是说,更简单的布局可能会从改进中获益更多。因此,为了回答您的问题,我们可以假设它们的效率存在差异。如果它们是可测量的,甚至是可察觉的另一个问题。

相关问题