SPAN in Android TableLayout

SPAN in Android TableLayout 

Today I realised that there should be a SPAN capability in the TableLayout (as similar to HTML table).
Before providing a complete example, some attribute discussed here which is used in TableLayout
android:layout_span        =      colspan in html table
android:padding            =      margin in html table
android:paddingLeft        =      left margin in html table  
android:paddingRight       =      right margin in html table  
android:paddingTop         =      top margin in html table 
android:paddingBottom      =      bottom margin in html table  
android:layout_gravity     =      align html table left, right, centre, top, bottom
android:background         =      background color of html table
android:layout_width       =      width of html table
android:layout_height      =      height of html table

Some units which are used in android

px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters). 




Layout File (main.xml)

<?xml version="1.0" encoding="utf-8"?>
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height=" wrap_content"
        android:layout_gravity="center_horizontal"
        android:background="#aa0000"
        android:padding="10dp" >
        
        <TableRow
            android:id="@+id/tableRow1"
            android:background="#00aa00"           
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_span="2"
                android:text="@string/title"
                android:textAppearance="?android:attr/textAppearanceMedium" />

        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Username"              
                android:textStyle="bold" />

            <EditText
                android:id="@+id/editText1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"               
                android:ems="10" >             
               
            </EditText>

        </TableRow>

        <TableRow
            android:id="@+id/tableRow3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Password"               
                android:textStyle="bold" />

            <EditText
                android:id="@+id/editText2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ems="10"
                android:inputType="textPassword" />

        </TableRow>

        <TableRow
            android:id="@+id/tableRow4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Email ID"               
                android:textStyle="bold" />

            <EditText
                android:id="@+id/editText3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ems="10"
                android:inputType="textEmailAddress" />

        </TableRow>

        <TableRow
            android:id="@+id/tableRow5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
            <TableLayout android:layout_span="2" >
            <TableRow >

            <CheckBox
                android:id="@+id/checkBox1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="12sp"
                android:text="Married" />

            <CheckBox
                android:id="@+id/checkBox2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="12sp"
                android:text="Employed" />

            <CheckBox
                android:id="@+id/checkBox3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="12sp"
                android:text="Graduate" />

                </TableRow>
               
            </TableLayout>
          

        </TableRow>
        <TableRow android:background="#00aa00"
            >

            <TextView
                android:id="@+id/textView6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_span="2"
                android:text=" " />

              </TableRow>
        <TableRow
            android:id="@+id/tableRow6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <Button
                android:id="@+id/button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"                             
                android:text="Save" />

            <Button
                android:id="@+id/button2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:text="Reset" />

        </TableRow>

    </TableLayout>

No comments:

Post a Comment