RelativeLayout

Android RelativeLayout enables you to specify how child views are positioned relative to each other. The position of each view can be specified as relative to sibling elements or relative to the parent.

1. RelativeLayoutAndroidExample.java

package com.tutorialsee.relativelayout;

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

public class RelativeLayoutAndroidExample 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_relative_layout_android_example);
}
}

2. activity_relative_layout_android_example.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    tools:context=".RelativeLayoutAndroidExample" >

    <TextView
        android:id="@+id/text1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerInParent="false"
        android:background="#009688"
        android:gravity="center"
        android:padding="5dp"
        android:text="LOGIN"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#ffffff"
        android:textSize="15sp" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/editText2"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/textView1"
        android:ems="10" />

    <Button
        android:id="@+id/btnSubmit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="false"
        android:layout_below="@+id/editText2"
        android:layout_centerInParent="true"
        android:layout_marginTop="15dp"
        android:background="#009688"
        android:paddingBottom="5dp"
        android:paddingLeft="25dp"
        android:paddingRight="25dp"
        android:paddingTop="5dp"
        android:text="Submit"
        android:textColor="#ffffff" />

    <RelativeLayout
        android:id="@+id/cxcx"
        android:layout_width="match_parent"
        android:layout_height="0.1dp"
        android:layout_below="@+id/btnSubmit"
        android:layout_marginTop="5dp"
        android:background="#009688"
        android:orientation="horizontal" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/cxcx" >

        <TextView
            android:id="@+id/lblComments"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:padding="10dp"
            android:text="Comments"
            android:textSize="20dp" />

        <EditText
            android:id="@+id/txtComments"
            android:layout_width="match_parent"
            android:layout_height="170dp"
            android:layout_alignLeft="@+id/lblComments"
            android:layout_below="@+id/lblComments"
            android:layout_centerHorizontal="true"
            android:layout_margin="3dp"
            android:background="#3362"
            android:textSize="18sp" />

        <Button
            android:id="@+id/btnSave"
            android:layout_width="125dp"
            android:layout_height="wrap_content"
            android:layout_alignRight="@+id/txtComments"
            android:layout_below="@+id/txtComments"
            android:layout_margin="3dp"
            android:background="#f7991c"
            android:padding="5dp"
            android:text="Save"
            android:textColor="#fff"
            android:textStyle="bold" />

        <Button
            android:id="@+id/button1"
            android:layout_width="125dp"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/btnSave"
            android:layout_alignBottom="@+id/btnSave"
            android:layout_alignParentLeft="true"
            android:layout_margin="3dp"
            android:background="#3b7bea"
            android:padding="5dp"
            android:text="Delete"
            android:textColor="#fff"
            android:textStyle="bold" />
    </RelativeLayout>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:background="#009688"
        android:padding="8dp"
        android:text="SIGNUP"
        android:textColor="#ffffff" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView2"
        android:layout_alignBottom="@+id/textView2"
        android:layout_alignParentRight="true"
        android:ems="10"
        android:inputType="textPassword" >
    </EditText>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/editText1"
        android:layout_marginTop="20dp"
        android:text="Password :"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="15sp" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/text1"
        android:layout_marginTop="10dp"
        android:text="Username :"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="15sp" />

</RelativeLayout>