What is the difference between linear and relative layout?
difference is simple: in LinearLayout we arrange stuff in linear manner (one after another), and in RelativeLayout we can place stuff anywhere on screen.
=> Linear Layout is arranged as a list. Rest they are similar in functionality.
In the relative layout ,all the content in the layout page is related to other contents in the example_layout.xml page
In the case of Linear Layout the elements are displayed in the linear format
LINEAR LAYOUT ::
Click here ---- for --- Android Docs reference for linear layout
RELATIVE LAYOUT::
Click here ---- for ---Android Docs reference for Relative layout
Optimization::Have a look at Optimizing Layout Hierarchies
The Fewer Views, the Better::
The number one goal for your layouts should be using the fewest number of Views possible. The fewer Views you have to work with, the faster your application will run. Excessive nesting of Views further slows down your application.
A RelativeLayout hierarchy will typically use fewer Views and have a flatter tree than a LinearLayout hierarchy. With LinearLayout, you must create a new LinearLayout every time you want to change the orientation of your views – creating additional Views and a more nested hierarchy. As a result, it is recommended that you first use RelativeLayout for any layout that has any complexity. There is a high probability you will reduce the number of Views – and the depth of your View tree – by doing so.
Linear Layouts
Relative Layouts
RelativeLayout
is more flexible than LinearLayout
but if you have proper knowledge about LinearLayout
you Can use that too.
For LinearLayout
every attribute has a significant position hardcoded by the developer.
For RelativeLayout
you can change the position by relating with others attribute.
The difference between linear and relative layout in android is that in linear layout, the "children" can be placed either horizontally or vertically, but, in relative layout, the children can be placed with relative distance from each other. This is the difference between linear and relative layouts.