Android Relative layout example

relativelayout.xml

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

    <Button
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:gravity="center"
        android:text="1"
        android:textSize="20dp"
        android:id="@+id/button"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@+id/button3"
        android:layout_toStartOf="@+id/button3"
        android:background="@drawable/color"
        android:textColor="#fff"/>
    <Button
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_centerHorizontal="true"
        android:gravity="center"
        android:text="2"
        android:textSize="20dp"
        android:id="@+id/button3"
        android:background="@color/colorAccent"
        android:textColor="#fff"/>
    <Button
        android:id="@+id/b3"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:text="3"
        android:textSize="20dp"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/button3"
        android:layout_toEndOf="@+id/button3"
        android:background="@drawable/color"
        android:textColor="#fff"/>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="57dp"
        android:id="@+id/linearLayout"
        android:layout_below="@+id/button"
        android:layout_alignLeft="@+id/button"
        android:layout_alignStart="@+id/button"
        android:layout_alignRight="@+id/b3"
        android:layout_alignEnd="@+id/b3">

        <Button
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_gravity="center"
            android:text="4"
            android:textSize="20dp"
            android:background="@color/colorAccent"
            android:textColor="#fff"/>
        <Button
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_centerHorizontal="true"
            android:gravity="center"
            android:text="5"
            android:textSize="20dp"
            android:background="@drawable/color"
            android:textColor="#fff"
            />

        <Button
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_gravity="center"
            android:text="7"
            android:background="@color/colorAccent"
            android:textColor="#fff"
            android:textSize="20dp"/>

    </LinearLayout>

    <Button
        android:id="@+id/button4"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:gravity="center"
        android:text="7"
        android:textSize="20dp"
        android:layout_below="@+id/linearLayout"
        android:layout_alignLeft="@+id/linearLayout"
        android:layout_alignStart="@+id/linearLayout"
        android:background="@drawable/color"
        android:textColor="#fff"/>

    <Button
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_below="@+id/linearLayout"
        android:layout_toRightOf="@+id/button4"
        android:layout_toEndOf="@+id/button4"
        android:text="8"
        android:textSize="20dp"
        android:background="@color/colorAccent"
        android:textColor="#fff"/>
    <Button
        android:id="@+id/button5"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_marginLeft="100dp"
        android:layout_marginStart="100dp"
        android:layout_toEndOf="@+id/button4"
        android:layout_toRightOf="@+id/button4"
        android:text="9"
        android:textSize="20dp"
        android:layout_below="@+id/linearLayout"
        android:background="@drawable/color"
        android:textColor="#fff"/>

    <Button
        android:layout_marginTop="20mm"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_alignParentBottom="true"
        android:layout_toRightOf="@+id/button4"
        android:layout_marginBottom="13dp"
        android:textSize="20dp"
        android:text="0"
        android:background="@drawable/color"
        android:textColor="#fff"/>
</RelativeLayout>

0 comments: