I'm familiar with almost all the basic layouts in Android & understand when they are to be used. I know that a RelativeLayout
is to be used when elements in the UI are to positioned relative to each other, that a LinearLayout
is to be used when UI elements are to be displayed vertically or horizontally. So I was wondering if the ease of development was the only factor that determined what layout should be selected or if there was any performance factor involved. I mean I can lay out two ImageViews
vertically in Android using both LinearLayout
and RelativeLayout
, so why use a particular layout then?
Asked
Active
Viewed 55 times
0

Auro
- 1,578
- 3
- 31
- 62
-
1I think you covered the basics, and are simplifying the problem a little – OneCricketeer Sep 21 '16 at 02:57
-
If you can do something with LinearLayout or with RelativeLayout, use Linear- it lays out faster because it doesn't have to calculate rules. Relative layout becomes necessary when you have overlapping views, or complex layouts- there are things that you can do with relative that can't be done with linear. – Gabe Sechan Sep 21 '16 at 05:53
1 Answers
0
There are some performance gains for avoiding certain things, such as nesting RelativeLayout
(see this question). Also, the docs recommend making layouts shallow and wide, which can facilitated with RelativeLayout
, again for performance reasons.
However, often thinking about such things will be premature optimization for simple layouts, and you should use whatever makes the most sense for the situation.