What is the difference between linear and relative layout?
From Android developer documentation: Common Layout Objects
LinearLayout
LinearLayout aligns all children in a single direction — vertically or horizontally, depending on how you define the orientation attribute.
RelativeLayout
RelativeLayout lets child views specify their position relative to the parent view or to each other (specified by ID)
One of the characteristic feature of LinearLayout
in Android is use of a property called Weight, which app can specify using android:layout_weight
.
This attribute assigns an "importance" value to a view in terms of how much space it should occupy on the screen.
On the other hand, RelativeLayout
do not support weight or in other words, RelativeLayout
does not pay attention to android:layout_weight
. That's a property of LinearLayout.LayoutParams
, but not of RelativeLayout.LayoutParams
.
Linear layouts put every child, one after the other, in a line, either horizontally or vertically. With a relative layout you can give each child a LayoutParam that specifies exactly where is should go, relative to the parent or relative to other children.
The following link should explain visually how the layouts work "Visually"
http://www.droiddraw.org/
Add some components to the window and mess with layouts to see what happens this is how I learned what each one does.