LinearLayout

The LinearLayout is the most basic layout manager provided by Android. The LinearLayout organizes the child views either horizontally or vertically based on the specified orientation property. The value for orientation property can be either horizontal or vertical.

1. LinearLayout.java

package com.tutorialsee.linearlayout;

import com.tutorialsee.linearlayout.R;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.Window;
import android.view.WindowManager;

public class LinearLayout extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_linear_layout);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_linear_layout, menu);
return true;
}

}

2. activity_linear_layout.xml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:orientation="vertical"
        tools:context=".LinearLayout" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#009688"
                android:gravity="center"
                android:padding="5dp"
                android:text="LOGIN"
                android:textColor="#ffffff" />

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:paddingTop="10dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingLeft="10dp"
                    android:paddingTop="10dp"
                    android:text="Username" />

                <EditText
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="40dp"
                    android:layout_weight="0.50"
                    android:paddingTop="10dp" />
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:paddingTop="10dp" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="10dp"
                android:paddingTop="10dp"
                android:text="Password" />

            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginLeft="40dp"
                android:layout_weight="0.50"
                android:paddingTop="10dp" />
        </LinearLayout>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:layout_gravity="center"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="10dp"
            android:background="#009688"
            android:paddingLeft="15dp"
            android:paddingRight="15dp"
            android:text="BUTTON"
            android:textColor="#ffffff"
            android:textSize="15sp" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0.1dp"
            android:background="#009688"
            android:orientation="horizontal" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:layout_marginTop="10dp"
            android:orientation="horizontal" >

            <Button
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="2dp"
                android:layout_marginTop="2dp"
                android:background="#009688"
                android:text="Button 1"
                android:textColor="#fff"
                android:textStyle="bold" />

            <Button
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_margin="2dp"
                android:background="#009688"
                android:text="Button 2"
                android:textColor="#fff"
                android:textStyle="bold" />

            <Button
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_margin="2dp"
                android:background="#009688"
                android:text="Button 3"
                android:textColor="#fff"
                android:textStyle="bold" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0.1dp"
            android:background="#009688"
            android:orientation="horizontal" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:layout_marginTop="10dp"
            android:orientation="vertical" >

            <Button
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_margin="2dp"
                android:background="#009688"
                android:text="Button 1"
                android:textColor="#fff"
                android:textStyle="bold" />

            <Button
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_margin="2dp"
                android:background="#009688"
                android:text="Button 2"
                android:textColor="#fff"
                android:textStyle="bold" />

            <Button
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_margin="2dp"
                android:background="#009688"
                android:text="Button 3"
                android:textColor="#fff"
                android:textStyle="bold" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0.1dp"
            android:background="#009688"
            android:orientation="horizontal" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:layout_marginTop="10dp"
            android:orientation="vertical" >

            <Button
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:layout_margin="2dp"
                android:layout_weight="1"
                android:background="#009688"
                android:text="Button 1"
                android:textColor="#fff"
                android:textStyle="bold" />

            <Button
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_margin="2dp"
                android:layout_weight="2"
                android:background="#009688"
                android:text="Button 2"
                android:textColor="#fff"
                android:textStyle="bold" />

            <Button
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:layout_margin="2dp"
                android:layout_weight="3"
                android:background="#009688"
                android:text="Button 3"
                android:textColor="#fff"
                android:textStyle="bold" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0.1dp"
            android:background="#009688"
            android:orientation="horizontal" />
    </LinearLayout>

</ScrollView>