3

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.

user2469133
  • 1,940
  • 3
  • 21
  • 33

1 Answers1

4

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.

Community
  • 1
  • 1
Cehm
  • 1,502
  • 1
  • 12
  • 14
  • Well put by @Cehm, In order to be in a proper position to judge the performance load of individual view you can always debug using hierarchy viewer. 1) [Hierarchy Viewer Walkthrough](http://developer.android.com/tools/performance/hierarchy-viewer/index.html) 2) [Optimizing Your UI](http://developer.android.com/tools/debugging/debugging-ui.html) Look for the point "Performance indicators" under section "Working with an individual View in Tree View" – binaryKarmic Oct 28 '15 at 14:54