Introduction
In this article, I explain the Linear Layout in Android. In Linear Layout we can use two types of views, one is horizontal and the other is vertical. When we want a linear design or simple design, we use this type of Linear Layout otherwise a Relative Layout is usually used in Android view displays.
Here I will show you how to use a Linear Layout in Android. In this article I will take a Linear Layout and one inner Linear Layout as shown in the output below, the main layout will be a vertical layer and the inner one will be a horizontal layer.
Step 1
First of all, create a new Android application project as shown below.

Step 2
Now open the XML file as "res/layout/activity_main.xml" and update it with the following code. This XML code is only for the Linear Layout and the view inside it.
- <?xml version="1.0" encoding="utf-8"?>
- <!-- Parent linear layout with vertical orientation -->
- <LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <TextView
- android:id="@+id/textview1"
- android:layout_width="fill_parent" android:layout_height="wrap_content"
- android:text="Email:" android:padding="5dip"/>
- <EditText
- android:id="@+id/edittext1"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_marginBottom="10dip"
- android:text="@string/email" />
- <EditText
- android:id="@+id/edittex2"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_marginBottom="10dip" />
- <Button
- android:id="@+id/enter_btn"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="Enter" />
- <!-- Child linear layout with horizontal orientation -->
- <LinearLayout android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal" android:background="#2a2a2a"
- android:layout_marginTop="25dip">
- <TextView
- android:id="@+id/home_btn"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:gravity="center"
- android:padding="15dip"
- android:text="Home"
- android:textColor="#ffffff" />
- <TextView
- android:id="@+id/reset_btn"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:gravity="center"
- android:padding="15dip"
- android:text="Reset"
- android:textColor="#ffffff" />
- </LinearLayout>
- <TextView
- android:id="@+id/result_txtview"
- android:layout_width="fill_parent"
- android:layout_height="match_parent"
- android:text=" " />
- </LinearLayout>


Comments
Join the conversation! Your thoughts help the community grow.