My Life with Android
Introduction Android Componets UserInterface Advanced UI Data Storage Advanced Concepts Others New Studio

Android - Layout

An Android layout(simply view element container) is a class that handles arranging the way its children appear on the screen. Anything that is a View (or inherits from View) can be a child of a layout. All view elements like textbox, label, buttons etc need to be contained inside the layout.All of the layouts inherit from ViewGroup (which inherits from View) so you can nest layouts.To design UI for an App, you need to know about Android Layout. This Layout is in-turn contained in a layout file location inside res/layout directory of the Android app. An Android Activity uses the Android Layout & shows output on the screen.

The standard Layouts are:
1. LinearLayout
2. RelativeLayout
3. FrameLayout
4. TableLayout
5. AbsoluteLayout
6. GridLayout
7. List View
8. Grid View
Layout Description
Linear Layout LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally.
Relative Layout RelativeLayout is a view group that displays child views in relative positions.
Table Layout TableLayout is a view that groups views into rows and columns.
Absolute Layout AbsoluteLayout enables you to specify the exact location of its children.
Frame Layout The FrameLayout is a placeholder on screen that you can use to display a single view.
List View ListView is a view group that displays a list of scrollable items.
Grid View GridView is a ViewGroup that displays items in a two-dimensional, scrollable grid.

Layout Attributes

Each layout has a set of attributes which define the visual properties of that layout. There are few common attributes among all the layouts. Following are common attributes and will be applied to all the layouts:
Attribute Description
android:id This is the ID which uniquely identifies the view.
android:layout_width This is the width of the layout.
android:layout_height This is the height of the layout
android:layout_marginTop This is the extra space on the top side of the layout.
android:layout_marginBottom This is the extra space on the bottom side of the layout.
android:layout_marginLeft This is the extra space on the left side of the layout.
android:layout_marginRight This is the extra space on the right side of the layout.
android:layout_gravity This specifies how child Views are positioned.
android:layout_weight This specifies how much of the extra space in the layout should be allocated to the View.
android:layout_x This specifies the x-coordinate of the layout.
android:layout_y This specifies the y-coordinate of the layout.
android:layout_width This is the width of the layout.
android:paddingLeft This is the left padding filled for the layout.
android:paddingRight This is the right padding filled for the layout.
android:paddingTop This is the top padding filled for the layout.
android:paddingBottom This is the bottom padding filled for the layout.