Android LinearLayout Example


In Android application, an activity displays the user interface (UI).

An activity provides a screen with Views and ViewGroups.

A View represents a widget such as button, label, text field…

A ViewGroup is a container that can group other Views or other ViewGroups.

The LinearLayout is a ViewGroup providing a layout in which views are ordered in a single column (vertical orientation) or a single row (horizontal orientation).

In this example, we will see how to use the LinearLayout to arrange our views and define their layout properties.

We will use XML to define our layout.


1. Technologies used

  • JDK 1.6
  • Eclipse 4.4 (Luna)
  • Android SDK Tools 23.0.2
  • Android 4.4.2 (KitKat)


2. Vertical orientation

LinearLayout with vertical orientation :


Result :



3. Horizontal orientation

LinearLayout with horizontal orientation :


Result :



3. Mixed orientation

In the same container, we can combine vertical and horizontal orientation to create our UI :


Result :



Download source code