简体   繁体   English

ConstraintLayout 是否仍然优于 Jetpack Compose 中的嵌套列和行?

[英]Is ConstraintLayout still preferred over nested Column & Row in Jetpack Compose?

Before Compose, when creating complex UI with XML, it's recommended to avoid nesting views ( RelativeLayout and LinearLayout ), and encouraged to use ConstraintLayout for achieving complex layouts.在 Compose 之前,使用 XML 创建复杂的 UI 时,建议避免嵌套视图( RelativeLayoutLinearLayout ),并鼓励使用ConstraintLayout来实现复杂的布局。

Now Compose has come out, and just by looking at it, ConstraintLayout in Compose was so complicated to understand, from my perspective—it's taking more time to figure out how the view should look like with ConstraintLayout than with nested Column and Row .现在 Compose 已经问世了,单看它,Compose 中的ConstraintLayout很难理解,从我的角度来看——与嵌套的ColumnRow相比,要弄清楚视图应该如何使用ConstraintLayout需要更多的时间。

Honestly, I'd rather go with nested Column and Row than ConstraintLayout in Compose, but I'm not sure about its drawbacks.老实说,我宁愿 go 与 Compose 中的ConstraintLayout嵌套ColumnRow ,但我不确定它的缺点。

Short answer: No, nested Row s/ Column s should be fine.简短的回答:不,嵌套的Row s/ Column应该没问题。


Compose is designed to reduce the penalty for nesting layouts, and allow for layouts to be more easily...well, composed . Compose 旨在减少对嵌套布局的惩罚,并使布局更容易......好吧,组合 The View system requires non-trivial overhead for each View you create, so it was encouraged to avoid nesting them more than necessary and creating extra View s. View 系统对您创建的每个View都需要不小的开销,因此鼓励避免不必要地嵌套它们并创建额外的View

While it's hard to say that there are no situations in which nesting Row s and Column s will cause a performance problem where ConstaintLayout would work well, you shouldn't immediately jump to ConstraintLayout when using nested Row s/ Column s would allow you to more easily express your desired layout.虽然很难说嵌套RowColumn不会导致ConstaintLayout工作良好的性能问题,但在使用嵌套Row s/ Column时不应该立即跳转到ConstraintLayout可以让您更多轻松表达您想要的布局。


Note that currently Compose is pre-stable, so performance characteristics are subject to change (generally for the better) as development continues.请注意,当前 Compose 是预先稳定的,因此随着开发的继续,性能特征可能会发生变化(通常会变得更好)。

Compose handles nested layouts efficiently, making them a great way to design a complicated UI. Compose 可以有效地处理嵌套布局,使其成为设计复杂 UI 的好方法。 This is an improvement from Android Views, where you need to avoid nested layouts for performance reasons.这是对 Android 视图的改进,出于性能原因,您需要在其中避免嵌套布局。

from Android doc来自Android 文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM