Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which order of nested layouts is most efficient in Android

I don't think I have really ever nested more than about three levels worth of Layouts (RelativeLayout, LinearLayout, FrameLayout) in Android. I am not thinking about list items which also use a custom layout for ListView but just normal layouts for an activity.

To the point though, I was chatting with another developer about nesting layouts for a certain layout we were discussing and he seemed to think that even a few nested layouts really slowed down performance. I figured there is some truth but it cant be that much.

Does anyone have a more expert approach to this? Any input? Opinion?

Thanks.

UPDATE for those who found on Google: The first answer below is a great resource. It looks like a lot and people seem to skip over answers like that but please check it out. Very valuable.

like image 888
Anthony Graglia Avatar asked Mar 21 '11 12:03

Anthony Graglia


People also ask

Which layout is more efficient?

The Colemak layout is arguably the best in terms of efficiency, and ease of use when coming from QWERTY, however, you would need to download a third-party application that does not remap the Backspace with Caps Lock as in a true Colemak layout.

Which nested layout performs better with execution time?

The flatter your hierarchy, the less time that it takes for the layout stage to complete. If you are using the RelativeLayout class, you may be able to achieve the same effect, at lower cost, by using nested, unweighted LinearLayout views instead.

Which is fastest layout in Android?

Results show that the fastest layout is Relative Layout, but difference between this and Linear Layout is really small, what we can't say about Constraint Layout. More complex layout but results are the same, flat Constraint Layout is slower than nested Linear Layout.


1 Answers

I guess there is no silver bullet for this but I will give you some tips:

1) Try using the tools provided with the android sdk.

I tend to analyze my layouts with hierarchyviewer and layoutopt trying to reduce the amount of View used and the height of the tree.

2) Read Romain Guy's posts about <include>, <merge> and <ViewStub> These tags are not used often but they provide great speed "hacks".

  • http://www.curious-creature.org/2009/03/01/android-layout-tricks-3-optimize-part-1/
  • http://www.curious-creature.org/2009/03/16/android-layout-tricks-4-optimize-part-2/

3) Use dmtracedump and measure how long does it take to inflate a view.

You can check how long it takes to inflate a view. Get an inflater and measure how long it takes to inflate each of your options.

like image 190
Macarse Avatar answered Oct 21 '22 14:10

Macarse