The literal understanding of tablelayout is a tabular layout. Such a layout arranges the included elements in the form of 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
Execution 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 co-owned 3 rows. That is, 3 TableRow, each with two cells inside each tablerow.
The tablelayout tag defines a table layout (tablelayout).
The TableRow tag defines a row inside the table layout.
Each line is free to add some components. For example, we mainly add the button component and the edit box component on top.
Java source 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