The literal understanding of tablelayout is a tabular layout. This layout arranges the contained elements in rows and columns. The number of columns in the table is the maximum number of columns per row. Of course, the cells inside the table can be empty.
Example: Layoutdemo
Operating effect:
Code Listing:
Layout file: Table_layout.xml
<?xml version= "1.0" encoding= "Utf-8"? ><tablelayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Match_parent "android:layout_height=" Match_parent "android:stretchcolumns=" 1 "& Gt <TableRow> <textview android:gravity= "right" android:textstyle= "bold" and roid:padding= "3dip" android:text= "User name:"/> <edittext android:id= "@+id/username "Android:padding=" 3dip "android:scrollhorizontally=" true "/> </TableRow> < tablerow> <textview android:gravity= "right" android:textstyle= "bold" Android :p adding= "3dip" android:text= "User password:"/> <edittext android:id= "@+id/password" android:padding= "3dip" android:password= "true"/> </TableRow> <tablerow Andro Id:gravity= "Right" > <button android:id= "@+id/cancel" android:text= "Cancel"/> <button an Droid:id= "@+id/login" android:text= "Login"/> </TableRow></TableLayout>
In the above layout code a total of 3 lines, namely 3 TableRow, each TableRow inside has two cells.
The tablelayout tag defines a table layout (tablelayout).
The TableRow tag defines a row inside the table layout. Each line is free to add components, such as on top of which we have mainly added button components and edit box components.
Java source code file: Tablelayoutactivity.java
Package Com.rainsong.layoutdemo;import Android.app.activity;import Android.os.bundle;public class Tablelayoutactivity extends activity{ /** called when the Activity is first created. */ @Override public Void OnCreate (Bundle savedinstancestate) { super.oncreate (savedinstancestate); Setcontentview (r.layout.table_layout); }}
Tablelayout of the Android UI layout