If I have just a single LinearLayout with a few items in it, then what effects will be of replacing it with ConstraintLayout
<LinearLayout>
<TextView>
<TextView>
<TextView>
</LinearLayout>
vs
<ConstraintLayout>
<TextView>
<TextView>
<TextView>
</ConstraintLayout>
Are there any differences in their efficiencies?
ConstraintLayout has flat view hierarchy unlike other layouts, so does a better performance than relative layout. Yes, this is the biggest advantage of Constraint Layout, the only single layout can handle your UI. Where in the Relative layout you needed multiple nested layouts (LinearLayout + RelativeLayout).
More complex layout but results are the same, flat Constraint Layout is slower than nested Linear Layout. I want to pay attention to 2 more things which are more subjective. Creating Constraint Layout takes more time than other layouts. Also introducing changes in existing Constraint Layout is much more time-consuming.
Most of what can be achieved in LinearLayout and RelativeLayout can be done in ConstraintLayout. However, learning the basics of LinearLayout and RelativeLayout is important before trying to understand how to use it with ConstraintLayout.
LinearLayout : is a ViewGroup that aligns all children in a single direction, vertically or horizontally. RelativeLayout : is a ViewGroup that displays child views in relative positions.
For such a simple layout with no nesting and only 3 children TextView, LinearLayout is the best on conceptual complexity, on performance, on drag and drop user interface of Android Studio, on XML lines, on kB size of the app. Maybe I forgot something, but I would not dare to waste time and mess things with any other layout than the LinearLayout in this case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With