Create an application for demonstration of Relative and Table Layout in android.

Activity_Main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TableLayout
    
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:shrinkColumns="*"
            android:stretchColumns="*"
            android:background="#ffffff"
            android:layout_marginTop="20dp">
   
           
    <TableRow
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:gravity="center_horizontal"
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="18dp"
            android:text="Row 1" 
            android:layout_span="3"
            android:padding="18dip"
            android:background="#b0b0b0"
            android:textColor="#000"
            android:gravity="center"/> 
    </TableRow> 
    
   
    <TableRow
        android:id="@+id/tableRow1"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        <TextView
            android:id="@+id/TextView04"
            android:text="Row 2 column 1"
            android:layout_weight="1"
            android:background="#dcdcdc"
            android:textColor="#000000"
            android:padding="20dip"
            android:gravity="center"/> 
        <TextView
            android:id="@+id/TextView04"
            android:text="Row 2 column 2"
            android:layout_weight="1"
            android:background="#d3d3d3"
            android:textColor="#000000"
            android:padding="20dip"
            android:gravity="center"/>
        <TextView
            android:id="@+id/TextView04"
            android:text="Row 2 column 3"
            android:layout_weight="1"
            android:background="#cac9c9"
            android:textColor="#000000"
            android:padding="20dip"
            android:gravity="center"/>
    </TableRow>
    
   
    <TableRow
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:gravity="center_horizontal"
        <TextView
            android:id="@+id/TextView04"
            android:text="Row 3 column 1"
            android:layout_weight="1"
            android:background="#b0b0b0"
            android:textColor="#000000"
            android:padding="20dip"
            android:gravity="center"/>
            
        <TextView
            android:id="@+id/TextView04"
            android:text="Row 3 column 2"
            android:layout_weight="1"
            android:background="#a09f9f"
            android:textColor="#000000"
            android:padding="20dip"
            android:gravity="center"/> 
    </TableRow>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent" >

        <Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/button1"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="53dp"
            android:text="Relative Button 1" />

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginTop="65dp"
            android:text="Relative Button 3" />

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/button3"
            android:layout_alignParentRight="true"
            android:text="Relative Button 2" />
    </RelativeLayout>
    
</TableLayout>

</LinearLayout>

Post a Comment

0 Comments