Search code examples
androidxmlkotlinandroid-layoutandroid-jetpack-compose

Why aren't we using ConstraintLayout in Jetpack compose as much as we did in XML?


I've been reviewing codes and I realized we don't use ConstraintLayout as often as we did in XML.

In XML we were encouraged to use ConstraintLayout due to the performance concerns instead of those nested layouts but now I see many codes with several columns and rows which could be easily replaced by ConstraintLayout.

Is there any reason behind this?


Solution

  • In Jetpack Compose, nesting layouts doesn't hurt performance as much as it did in the old View system. This lets you build layouts more intuitively by combining simpler building blocks. While ConstraintLayout might be better in some specific cases, using nested Rows and Columns is generally a good choice for readability and maintainability.

    Also, we can still go for ConstraintLayout in jetpack compose when we have that complex UI to create. Hope this answer helps.

    Note: Compose handles nested layouts efficiently, making them a great way to design a complicated UI. This is an improvement from Android Views, where you need to avoid nested layouts for performance reasons.

    Android Doc