I am new to android layouts, Could please tell me how the performance of application when using nested layouts instead of using layout below, layout above, layout right, layout left attributes of relative layout for components.
For eg:
<RelativeLayout>
<scrollView>
<RelativeLayout>
<LinearLayout> Header<LinearLayout>
<TextView/> <TextView/>
<TableLayout>
<TableRow><ImageView/> <TextView> <Spinner><TableRow>
<TableRow><ImageView/> <TextView> <Spinner><TableRow>
<TableRow><ImageView/> <TextView> <Spinner><TableRow>
<TableRow><ImageView/> <TextView> <Spinner><TableRow>
</TableLayout>
<TextView>
<TableLayout>
<TableRow>
<LinearLayout> <ImageView><TextView></LinearLayout>
<EditText>
</TableRow>
<TableRow>
<LinearLayout> <ImageView><TextView></LinearLayout>
<EditText>
</TableRow>
<TableRow>
<TextView>
< Spinner>
</TableRow>
<TableRow><TextView> <Spinner></TableRow>
</TableLayout>
<TableLayouts>---</TableLayout>
<LinearLayout> footer</LinearLayout>
</RelativeLayout>
<ScrollView>
</RelativeLayout>
Thanks & Regards Yamini
Android LinearLayout In this layout we have a Parent LinearLayout which has a vertical orientation and contains buttons, textviews and a nested Linear Layout(having a horizontal orientation) as child views.
You will find that there're a lot of different, if your Pages loading some images from internet. In this case the LinearLayout is 100% better than RelativeLayout ever.
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.
Consider using flatter layouts such as RelativeLayout or GridLayout to improve performance. The default maximum depth is 10.
Well some layouts can only be made by doing some level of nesting. But you should avoid having too many nested LinearLayouts and even more important NEVER nest LinearLayouts with weights. You can read a little more about optimizing layouts in the official docs.
Personally I use LinearLayouts for simple stuff and start using RelativeLayout when the layout gets more complex. There is no one answer as it is a matter of preference.
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