articles

Home / DeveloperSection / Articles / Android Layout and its Type

Android Layout and its Type

Arti Mishra2909 06-Apr-2018

Android Layouts

A layout defines the structure for a user interface (UI) in your android app, and it also manage all the component in your app. All elements in the layout are built using a view hierarchy and View Group objects. A view is a rectangular area on your android app where we can display UI components & it’s usually draws something the user can see and interact with. Whereas a ViewGroup is an invisible container that defines the layout structure for View and another ViewGroup objects. Each layout file must contain exactly one parent element or root element. Once you've defined the root element in your view, you can add additional layout objects or widgets as child elements to build a View hierarchy that defines your layouts. 

Android Layout and its Type

Types of layout in Android

1. Linear Layout

Linear layout is special types of layout that arrange the component in either horizontal or vertical. In other words you can say that linear layout is a view group that aligns all children in a single direction, either vertically or horizontally. You can specify the layout direction by using android:orientation attribute. 

Android Layout and its Type

2. Relative Layout

Relative Layout is a view group that enables you to specify how child views are position relative to each other. It also allow you to position the component anywhere you want, so it is considered as most flexible layout.

In Relative Layout, you can also use above, below, left and right position to arrange the component’s relative to other component.  

Android Layout and its Type

3. Table Layout 

Android Table Layout is used to arrange the component or group of view in rows and columns form.

You will use <TableRow> tag to arrange the component in particular row in the table. And each row have zero or more columns, each column can hold one view object at a time. 

Android Layout and its Type

4. Absolute Layout

Absolute Layout is used to arrange the component as exact location of it children. And it also manage the particular component as exact x & y co-ordinates.Absolute layouts are less flexible and so hard to maintain than other types of layouts.

Android Layout and its Type

5. Frame Layout

Frame layouts are special types of layout that is used to organize controls within the user interface of an Android application. Which allows User Interface widgets to be overlapped with each other. It’s used in such cases where placing a TextView over an ImageView. Here we display simple frame layout -

Android Layout and its Type

6. Constraint Layout

Constraint Layout is used to build a responsive layout in our android app. And it is also allows you to create large & complex layout that is portable for all android screens. It’s similar to relative layout in that manner where all views are laid out according to relationships between its siblings but it also contain our own extra feature.& more flexible than relative layout.

Constraints Layout allow you to position a given widget or component relative to each other. You can constraint a widget or component on the horizontal and vertical axis. Below we explain how to apply constraint layout in any UI widgets.

Android Layout and its Type

Creating a new layout file

When adding a new layout for your android app, first you can create a layout file in your projects. Once you have create layout file, you can also create layout variations for specific device configurations (such as for xl screens).

There are some different ways to create a new layout file, depending on your Project window view, but the following procedure is accessible from any view.

1. In the Project window, click the app module in which you want to add a layout file.

2. In the main menu, select File > New > XML > Layout XML File.

3. Enter a name for the file in the dialog box that appears, the root layout tag, and the source set in which the layout belongs. Then click on Finish.

Another ways to create a new layout file (although the dialogs that appear are different) are as follows:

• If you've selected the Project view in the Project window: open the res directory for your app module, right-click the layout directory where you'd like to add the layout file and then click New > Layout resource file.

• If you've selected the Android view in the Project window: right-click the layout folder and then select New > Layout resource file.



Updated 07-Sep-2019

Leave Comment

Comments

Liked By