Learn to literally tablelayout a table-style layout. This layout will include elements that are arranged in the form of rows and columns. The number of table columns is the maximum number of rows in the column. Of course, the cells inside the table can be emptied.
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 "> <TableRow> <TEXTV Iew android:gravity= "Right" android:textstyle= "bold" android:padding= "3dip" an droid:text= "User name:"/> <edittext android:id= "@+id/username" android:padding= "3di P "android:scrollhorizontally=" true "/> </TableRow> <TableRow> <textview Android:gravity= "Right" android:textstyle= "bold" android:padding= "3dip" Androi d:text= "User password:"/> <edittext android:id= "@+id/password" android:padding= "3dip" Android:password= "true"/> </TableRow> <tablerow android:gravity= "right" > < ; Button Android:id= "@+id/Cancel "android:text=" cancels "/> <button android:id=" @+id/login "Android : text= "Login"/> </TableRow></TableLayout>
In the above layout code, a co-owned 3 lines, 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 can be freely added to some components, for example, on top of which we have mainly added the button component and the edit box component.
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); }}
Android UI Layout Tablelayout