3

There are quite a few articles on the performance of Relative and Linear Layouts. Using Nested LinearLayout would cost in traversals because of the bigger view hierarchy. I don't know why it is not preferable to use RelativeLayout every time as I heard it in Google I/O 2013 but the reason was not given in that video

Is there anyone who can help us understand the in-depth concepts (Performance, resource costs etc.) behind these layouts.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
codepeaker
  • 420
  • 8
  • 15
  • 2
    AFAIK, there is no single universal answer to this question. As with many things in programming, the real answer is "it depends on circumstances". – CommonsWare Dec 22 '16 at 18:41
  • @cricket_007 Dude i have read it already but it is not a complete answer. :( – codepeaker Dec 22 '16 at 18:43
  • @CommonsWare can you please elaborate those possibilities. – codepeaker Dec 22 '16 at 18:46
  • What more are you looking for? The true answer here is "it depends on what you want to display". Like if you want a grid, use a grid or table layout, a list of data goes in a ListView, etc – OneCricketeer Dec 22 '16 at 18:46
  • I think at the latest Google I/O's the ConstraintLayout is claimed to be superior to even RelativeLayout – OneCricketeer Dec 22 '16 at 18:48
  • @cricket_007 Let me see that one – codepeaker Dec 22 '16 at 18:53
  • https://developer.android.com/training/constraint-layout/index.html – OneCricketeer Dec 22 '16 at 18:55
  • I would add: those two are not entirely interchangeable; RelativeLayout can do things that LinearLayout can not, so if you need them then there is no comparison. If you only need to arrange things linearly, then use LinearLayout since it is conceptually simpler. Otherwise, you need to create your specific use of them in each and measure it. – dsh Dec 22 '16 at 19:00

1 Answers1

3

RelativeLayout is measured twice, so LinearLayout has better performance when used right.

Stefan
  • 2,098
  • 2
  • 18
  • 29
  • RelativeLayout is measured twice. What does it mean? – codepeaker Dec 22 '16 at 18:38
  • 2
    `LinearLayouts` also go through two measurement passes in some cases (e.g., using weights). – CommonsWare Dec 22 '16 at 18:40
  • 1
    True, relativelayout can be used in most cases as far as I know it. Unless you are creating complex layouts. This explains the measuring a little: http://stackoverflow.com/questions/28607737/in-android-what-layout-is-faster-1-framelayouts-inside-linearlayout-or-2-one – Stefan Dec 22 '16 at 18:42