Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 355
daya pangestu Avatar asked Feb 04 '23 14:02

daya pangestu


1 Answers

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.

like image 158
Ryan M Avatar answered Feb 06 '23 15:02

Ryan M