Friday, December 7, 2007

TableLayout Example

Today's sample code will implement very similar UI to the one created in the LinearLayout Example. But here we will be using a TableLayout widget instead.

Each TableLayout consists of a number of TableRow objects and each TableRow object contains zero or more cells. Each cell can hold one View object. The table has as many columns as the row with the most cells and cells can of course span columns. Here is a simple example of a "Sign In" form created with the TableLayout container:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:background="#000044">
<TableRow>
<TextView id="@+id/textName"
android:text="Name:"
android:textColor="#ffffff" />
<EditText id="@+id/editName"
android:width="240px" />
</TableRow>
<TableRow>
<TextView id="@+id/textPasswd"
android:text="Password:"
android:textColor="#ffffff" />
<EditText id="@+id/editPasswd"
android:password="true" />
</TableRow>
<TableRow>
<Button id="@+id/buttonSignIn"
android:text="Sign In" />
</TableRow>
</TableLayout>
Notice, that there aren't specified layout_width and layout_height attributes in the XML file. It's because TableRow always enforces those values to be respectively fill_parent and wrap_content.

Source: Google Android

9 comments:

Marvel said...

Try to enter long password and layout become screwed

VOIP Headphones said...

This is great. I just saw a review of Professional Android 2 Application Development and thought I would get into programming again.

This is cool.

Dj said...

Can we poistion the whole table ...
like
android:layout_x="125px"
android:layout_y="50px"

Programing Solution said...

Nice contents, you can get more android sample example, solution, tutorial and basic examples of the android programs, like gridview, progressdialog, readwrite sdcard, download data, simple buttonclick, etc on

http://android-solution-sample.blogspot.com

Thanks

Adobe flash crash said...

Hi..

Great tutorial i have learn a lot of things,
Thanks

Android app development said...

This is one of the Important post.Thanks for providing the Information about Android application.This is one of the suitable post.Android app developers

Forum hosting said...

It is actual accessible and advantageous one.Thanks for sharing.

Meghna said...

Thanks for the nice tutorial man... Even this
www.compiletimeerror.com/2013/07/android-tablelayout-example.html
might help, have a look...

Mobile App Developers said...

Hi, Really great effort. Everyone must read this article. Thanks for sharing.