Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Using too many linear layouts

Is it a bad practice to use too many linear layouts (20 for example) in a single xml view in android?

Does it cause slow rendering for example of the whole view.

I sometimes need to use too many weight attributes in a single view that's why i find my self using too many linear layouts.

like image 466
user2469133 Avatar asked Jul 12 '26 23:07

user2469133


1 Answers

I'm pretty sure it is. You should try avoiding using LinearLayout and use RelativeLayouts instead.

I know weights sound attractives but I'm sure you can think about a relativeLayout workeround.

Thing is, with LinearLayout, the UI is always computed, recomputed and recomputed etc, every time you need to update something. And ppl know nested stuffs are bad for perfs. 20 is really too much, I think you can do better ;)

See this answer for more information : Why are nested weights bad for performance? Alternatives?

Or from here : http://developer.android.com/training/improving-layouts/optimizing-layout.html

For example, using nested instances of LinearLayout can lead to an excessively deep view hierarchy. Furthermore, nesting several instances of LinearLayout that use the layout_weight parameter can be especially expensive as each child needs to be measured twice. This is particularly important when the layout is inflated repeatedly, such as when used in a ListView or GridView.

like image 184
Cehm Avatar answered Jul 15 '26 12:07

Cehm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!