Types of layout in Android
| Sr.No | Description |
|---|---|
| 1 | Linear Layout LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. |
| 2 | Relative Layout RelativeLayout is a view group that displays child views in relative positions. |
| 3 | Absolute Layout AbsoluteLayout enables you to specify the exact location of its children. |
| 4 | Table Layout TableLayout is a view that groups views into rows and columns. |
| 5 | Frame Layout The FrameLayout is a placeholder on screen that you can use to display a single view. |
| 6 | Grid View GridView is a ViewGroup that displays items in a two-dimensional, scrollable grid. |
| 7 | List View ListView is a view group that displays a list of scrollable items. |
Attributes of Layouts:
Each layout has a set of attributes which define the visual properties of that layout. There are few common attributes among all the layouts and their are other attributes which are specific to that layout. Following are common attributes and will be applied to all the layouts:
- android:id: It uniquely identifies the Android Layout.
- android:hint: It shows the hint of what to fill inside the EditText.
- android:layout_height: It sets the height of the layout.
- android:layout_width: It sets the width of the layout.
- android:layout_gravity: It sets the position of the child view.
- android:layout_marginTop: It sets the margin of the from the top of the layout.
- android:layout_marginBottom: It sets the margin of the from the bottom of the layout.
- android:layout_marginLeft: It sets the margin of the from the left of the layout.
- android:layout_marginRight: It sets the margin of the from the right of the layout.
- android:layout_x: It specifies the x coordinates of the layout.
- android:layout_y: It specifies the y coordinates of the layout.
1. Linear Layout
We use this layout to place the elements in a linear manner. A Linear manner means one element per line. This layout creates various kinds of forms on Android. In this, arrangement of the elements is in a top to bottom manner.
This can have two orientations:
a. Vertical Orientation – It is shown above where the widgets such as TextViews, and all in a vertical manner.
b. Horizontal Orientation – It is shown above where the widgets such as TextViews, and all in a horizontal manner.
2. Relative Layout
This layout is for specifying the position of the elements in relation to the other elements that are present there.
In the relative layout, alignment of the position of the elements to the parent container is possible. To define it in such a way, we write the following:
- android:layout_alignParentTop= “true”
- android:layout_alignParentLeft= “true”
If we write the above code, the element will get aligned on the top left of the parent container.
If we want to align it with some other element in the same container, it can be defined is as follows:
- android:layout_alignLeft= “@+id/element_name”
- android:layout_below= “@+id/element_name”
This will align the element below the other element to its left.
Comments
Post a Comment