Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
287 views
in Technique[技术] by (71.8m points)

android - 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.

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.

Honestly, I'd rather go with nested Column and Row than ConstraintLayout in Compose, but I'm not sure about its drawbacks.

question from:https://stackoverflow.com/questions/66058564/is-constraintlayout-still-preferred-over-nested-column-row-in-jetpack-compose

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Short answer: No, nested Rows/Columns should be fine.


Compose is designed to reduce the penalty for nesting layouts, and allow for layouts to be more easily...well, composed. 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 Views.

While it's hard to say that there are no situations in which nesting Rows and Columns will cause a performance problem where ConstaintLayout would work well, you shouldn't immediately jump to ConstraintLayout when using nested Rows/Columns would allow you to more easily express your desired layout.


Note that currently Compose is pre-stable, so performance characteristics are subject to change (generally for the better) as development continues.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...