Saturday, 28 July 2012

Android Table Layout Tutorial


Introduction of Android Table Layout


Every android control is put in predefined layout. layout provides to arrange android controls. Table layout used to define control in table format. Android uses table row concept. In table row we can define our new control.

How to define table layout

Android use seperate file for layout. This file stored in android res/layout directory.

syntex :
 <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tableLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
 
 <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dip">   
  
    put your control
    
 </TableRow>
 
  <TableLayout/>

 
Above syntex define following properties
  • android:layout_width this property is used to define width.
  • android:layout_height this property is used to define height.
Example
  1. Make layout file(main.xml).

    <?xml version="1.0" encoding="utf-8"?>
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/tableLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
     
     <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="5dip"> 
            
     <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button 1" />
     </TableRow>
             
     <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="5dip">      
              
     <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button 2" />
            
      </TableRow>
       
     </TableLayout>
    
  2. Output : 

   

No comments:

Post a Comment