Skip to content

Instantly share code, notes, and snippets.

@arod2634
Last active August 29, 2015 14:16
Show Gist options
  • Save arod2634/915e7aa5edd3003f902d to your computer and use it in GitHub Desktop.
Save arod2634/915e7aa5edd3003f902d to your computer and use it in GitHub Desktop.
Android Relative Layout Example
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="One"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Two"
android:id="@+id/textView2"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/textView"
android:layout_toEndOf="@+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Three"
android:id="@+id/textView3"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/textView2"
android:layout_toEndOf="@+id/textView2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Four"
android:id="@+id/textView4"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/textView3"
android:layout_toEndOf="@+id/textView3" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<TextView
android:layout_width="200dp"
android:layout_height="150dp"
android:text="One"
android:id="@+id/textView" />
<TextView
android:layout_width="200dp"
android:layout_height="150dp"
android:text="Two"
android:id="@+id/textView2"
android:layout_toRightOf="@+id/textView"/>
<TextView
android:layout_width="200dp"
android:layout_height="150dp"
android:text="Three"
android:id="@+id/textView3"
android:layout_below="@+id/textView" />
<TextView
android:layout_width="200dp"
android:layout_height="150dp"
android:text="Four"
android:id="@+id/textView4"
android:layout_toRightOf="@+id/textView3"
android:layout_below="@+id/textView2" />
</RelativeLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment