Today we are going to see the different layouts in Android.For that we need to understand what is layout.which are given below.
What is Layout?Layout is the architecture for user Interface(UI) in the activity.It defines layout structure and holds all the elements which are visible to the user.
How to declare Layout?
1. Declare UI element in XML.(Such as TextView, Button)
2. Create UI at run time.(in .java file)
Where to place XML file in your project.
your_project_name > res > layout > your_file_name.xml
Here we are declaring UI element in XML.We are not creating UI at run-time. So Lets start with Absolute Layout.Basically there are five layout's in Android. All layout's are subclass of ViewGroup.Explained below.
1. Absolute Layout
2. Frame Layout
3. Table Layout
4. Linear Layout
5. Relative Layout
1. Absolute Layout
Let’s start with Absolute layout. In Absolute Layout you have to mention X and Y coordinate of the screen for the respective component. This layout is not used for the development of UI. Because it is quite difficult to set absolute position of each element in the UI. Consider if we need to add or remove any component at that time we need to set the position of each and every component. I have designed Login page using Absolute Layout.2. Frame Layout
3. Table Layout
4. Linear Layout
5. Relative Layout
1. Absolute Layout
Here is the xml code for using Absolute Layout.
Here is the output of Absolute Layout.
In Frame Layout all the contents are placed in one frame. You can add multiple elements in it but all the component will overlap with each other. And top element will be visible to you. I have designed simple XML file using frame layout. In the sample xml file button is overlapping TextView hence the rest of text is visible to you.This is xml code for Frame Layout :-
This is the output for Frame Layout.
3. Table Layout
In Table Layout you have to put the contents in rows or in columns. TableRow is child view of the Table Layout. Where each table row defines one row in the table. Each row may contain one or more column. And columns are hidden in android. You have to stretch it and fill the available screen.
Here is xml code for Table Layout.
This is the output for Table Layout.
4. Linear Layout
In Linear Layout all the elements are placed in line by line either horizontally or vertically. I have designed simple login page using this layout. I have put the screen shot. If we put the orientation of the layout as vertical then we will be able to see the simple login page which is shone below.Where all the elements will be visible one after another. The .xml code for linear layout with vertical orientation is shown below.
This is output with vertical orientation.
But if we change the orientation from vertical to horizontal then we will not be able to see the rest of content. Since elements are placed in one by one fashion.Which will look in the next screen shot given below.
5. Relative Layout
In Relative Layout all the elements are placed in relative to each other. In this layout all the child are placed in relative to the parent view or each other. I have designed simple login page using Relative Layout.The .xml code for relative layout is given below.
This is the output for Relative Layout.
This is what the different layout's in Android.















