Thursday, 17 January 2013

Relative Layout Example in Android


main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="23dp"
        android:layout_marginTop="22dp"
        android:text="Name"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <EditText
        android:id="@+id/name_edit_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="23dp"
        android:layout_below="@id/textView1"
        android:ems="10" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/name_edit_text"
        android:layout_marginTop="24dp"
        android:layout_marginLeft="23dp"
        android:text="Password"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <EditText
        android:id="@+id/password_edit_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="23dp"
        android:layout_below="@id/textView2"
        android:ems="10"
        android:inputType="textPassword" />

    <Button
        android:id="@+id/login_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/password_edit_text"
        android:layout_marginTop="56dp"
        android:layout_toRightOf="@+id/textView2"
        android:text="Login" />

</RelativeLayout>


Output :



Source Code : Download this Example Here

No comments:

Post a Comment