Types of layout in Android

There are numer of layouts provide by android,android application developer used different layout to give different look to application.Layout basically refers to the arrangement of elements on a page these elements are likely to be images, texts or styles.These layouts can have various widgets like buttons, labels, textboxes, and many others.

Sr.NoDescription
1Linear Layout

LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally.

2Relative Layout

RelativeLayout is a view group that displays child views in relative positions.

3Absolute Layout

AbsoluteLayout enables you to specify the exact location of its children.

4Table Layout

TableLayout is a view that groups views into rows and columns.

5Frame Layout

The FrameLayout is a placeholder on screen that you can use to display a single view.

6Grid View

GridView is a ViewGroup that displays items in a two-dimensional, scrollable grid.

7List 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.

3. Absolute Layout

A layout that lets you specify exact locations (x/y coordinates) of its children. Absolute layouts are less flexible and harder to maintain than other types of layouts without absolute positioning.

4. Table Layout

Table layout positions its children into rows and columns. TableLayout containers do not display border lines for their rows, columns, or cells. The table will have as many columns as the row with the most cells. A table can leave cells empty. Cells can span multiple columns, as they can in HTML. 
5. Frame Layout
FrameLayout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view, because it can be difficult to organize child views in a way that's scalable to different screen sizes without the children overlapping each other.

6. Gridview Layout 

Android GridView shows items in two-dimensional scrolling grid (rows & columns) and the grid items are not necessarily predetermined but they automatically inserted to the layout using a ListAdapter.


7. ListView Layout

Android ListView is a view which groups several items and display them in vertical scrollable list. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array or database.







Comments

Popular posts from this blog

Constraint Layout with Appbar Layout

How to Create ImageButton With same Height and Width in Same Distance in Android