Hi, would you guys say it is legit to use `Constra...
# compose
l
Hi, would you guys say it is legit to use
ConstraintLayout
for all layouts. In non-compose layouts I used to use only
ConstraintLayout
for all layouts and never regret. I mean, are there any use cases where you would use
Rows/Columns
where
ConstraintLayout
wouldn't also fit?
b
I like to subscribe to the philosophy of whatever is the right tool for the job is the best tool. For example with Views: I use constraintlayouts for complex layouts that would require lots nested LinearLayouts/RelativeLayouts. But if I have a simple stack (say 3 image views horizontally aligned) I’ll use a LinearLayout. It’s easier to digest and seems like a better tool for the job. I’ve adapted that to compose as well. So if I know I have a simple stack, I’ll stick to a row/column. Complex layouts I’ll tend to use the constraint system.
5
g
It’s easier to digest and seems like a better tool for the job.
And also faster than ConstraintLayout especially if it nested
l
ok thanks guys. @gildor
And also faster than ConstraintLayout especially if it nested
Isn't it vice versa? ConstraintLayout vs. nested Rows/Columns performs better?
g
It depends on how nested they are. Frame layout for 1 view or simple list in linear layout are faster than Constraint Layout. nested constraint layouts is worse than 2 nested linear layout without weight
s
In XML, typically with a file for the entire screen, it's pretty costly to reverse the decision of the layout. As a result it's a pretty reasonable choice that a lot of people make to make every screen use ConstraintLayout "just in case" In Compose, changing layouts only impacts a single function typically so it's much less costly. You can easily switch from Row/Column to ConstraintLayout without restructuring all of your code. This lower cost to reverse suggests starting with the obvious solution and changing when needed. Also in Compose, making custom layouts is fairly easy to do compared to views. So you might start simple and jump straight to a custom layout when you have complex layout needs – skipping over ConstraintLayout completely. It really depends on the use case
l
Thanks for elaborating 🙂