Difference Between LinearLayout and RelativeLayout in Android
LinearLayout is a type of view group which is responsible for holding views in it either Horizontally or vertically. It is a type of Layout where one can arrange groups either Horizontally or Vertically.
RelativeLayout is a layout in which we can arrange views/widgets according to the position of other view/widgets. It is independent of horizontal and vertical view and we can arrange it according to one’s satisfaction.
Difference Between LinearLayout and RelativeLayout
|We can adjust views and widgets linearly i.e. Horizontally and vertically.||We can adjust views and widgets according to one’s satisfaction.|
layout_weight attribute in the linear layout is used to specify the equal or specific size to the particular widget and view by using the following attribute.
android:layout_weight = ‘0’
Here Weight is specified as 0 in order to give equal size or space to each view or widget.
|Various attributes like: layout_toRightOf, layout_toLeftOf, layout_below, layout_alignParentTop, layout_top, layout_alignParentLeft, layout_alignParentRight are used to specify the position of each view and widget.|
|It is useful when we arrange views in a linear fashion||It is useful when we arrange views in a relative fashion.|
|Example: In various Apps, LinearLayout is mainly applicable in the SignUp screen where Name, Email, Phone Number, Submit, etc. are arranged in a linear fashion.||Example: In Google Play Store, when we open the app, the games, books, movies, and App’s sections all are arranges in Relative Layout Fashion.|
|LinearLayout is less used as compared to RelativeLayout.||RelativeLayout is used more in applications.|
|We can use LinearLayout inside RelativeLayout.||We can also use RelativeLayout as a Child of LinearLayout.|
Program Explaining LinearLayout
Program Explaining RelativeLayout