Linear Layout in Android :

The Linear Layout is one among the simplest layout type. It allows you to make simple UIs (or UI elements) that align a sequence of child Views in either a vertical or a horizontal line.
The simplicity of the Linear Layout makes it easy to use but limits its flexibility. In most cases you’ll use Linear Layouts to construct UI components that will be nested within other layouts, like the Relative Layout.
android linear layout

Note : This example (Project) is developed in Eclipse Version Kepler, tested on Android 4.4.2 (KitKat Version) and SDK build-tools 22.6.3

Solution Stuff :

You have many options when arranging views using the Linear Layout:
They will be organized in a single column or a single row.
Child views may be arranged either vertically or horizontally.
Views may be aligned to certain sides of a screen, using weight specifications.
The following Lesson discuss these in more details.

Orientations :

You can set the orientation to display horizontally or vertically, so items appear in a single column or a single row.Should the layout be a column or a row? Use “horizontal” for a row, “vertical” for a column. The default is horizontal.

Horizontal Orientation :

android linear layout horizontal

Vertical Orientation :

Android linear layout vertical

Gravity and Weight :

Besides orienting  views either horizontally or vertically, you’ll be able to also specify a view’s gravity and weight. A view’s gravity indicates how the view should be placed in its container (so, alignment to the left, right or center). A view’s weight specifies its positioning with respect to the other views within the same container (it may be positioned on top of or below other items).

android layout linearFigure shows the positioning of the views as well as their height. The layout_gravity attribute indicates the position of the content, whereas the layout_weight attribute specifies the distribution of available area. in the preceding example, the 3 buttons occupy concerning 16.6% (1/(1+2+3) * 100),  33.3% (2/(1+2+3) * 100), and 50% (3/(1+2+3) * 100) of the available height, respectively.

Android linear layout Example Source code Download :

Leave a Reply