TableLayout in Android

A TableLayout is used to arrange child views in rows and columns. The TableLayout class is a subclass of LinearLayout. To add a row in a TableLayout, use a TableRow element. A view directly added to a TableLayout (without a TableRow) will also occupy a row that spans all columns.

Example of TableLayout

<TableLayout

xmlns:android=“http://schemas.android.com/apk/res/android”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_gravity=“center” >

<TableRow

android:id=”@+id/tableRow1”

android:layout_width=“500dp”

android:layout_height=“wrap_content”

android:padding=“5dip” >

<ImageView android:src=”@drawable/ic_launcher” />

<ImageView android:src=”@android:drawable/btn_star_big_on” />

<ImageView android:src=”@drawable/ic_launcher” />

</TableRow>

<TableRow

android:id=”@+id/tableRow2”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content” >

<ImageView android:src=”@android:drawable/btn_star_big_off” />

<TextClock />

<ImageView android:src=”@android:drawable/btn_star_big_on” />

</TableRow>

<EditText android:hint=“Your name” />

<Button

android:layout_height=“wrap_content”

android:text=“Go” />

</TableLayout>

Leave a Reply

Your email address will not be published. Required fields are marked *