在 Jetpack Compose 中,ConstraintLayout 是否仍然优于嵌套的 Column & Row?

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

在 Compose 之前,当使用 XML 创建复杂的 UI 时,建议避免嵌套视图(RelativeLayoutLinearLayout),并鼓励使用 ConstraintLayout 用于实现复杂的布局。

现在 Compose 出来了,只是看一下,Compose 中的 ConstraintLayout 太难理解了,从我的角度来看——需要更多时间来弄清楚视图应该是什么样子 ConstraintLayout 而不是嵌套 ColumnRow.

老实说,我宁愿在 Compose 中使用嵌套的 ColumnRow 而不是 ConstraintLayout,但我不确定它的缺点。

简短回答:不,嵌套 Rows/Columns 应该没问题。


Compose 旨在减少嵌套布局的损失,并允许布局更容易......好吧,composed。 View 系统需要为您创建的每个 View 带来不小的开销,因此我们鼓励避免不必要地嵌套它们并创建额外的 View

虽然很难说 没有 嵌套 RowColumn 会导致性能问题的情况 ConstaintLayout 会很好,当使用嵌套 Rows/Columns 时,您不应该立即跳转到 ConstraintLayout 可以让您更轻松地表达您想要的布局。