The main idea is how to design a tablelayout + tablerow In the UI Designer. in practical applications, you often need to add data to tablelayout in the Code (tablelayout can also be used for 9 gongtu ), this article describes how to use
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TableLayout android:id="@+id/TableLayout01" android:layout_width="fill_parent" android:layout_height="wrap_content"> </TableLayout></LinearLayout>
Package mas. layout02; import android. app. activity; import android. OS. bundle; import android. view. viewgroup; import android. widget. tablelayout; import android. widget. tablerow; import android. widget. textview; public class tabletest extends activity {/** called when the activity is first created. */private final int WC = viewgroup. layoutparams. wrap_content; private final int fp = viewgroup. layoutparams. fill_parent; @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); // create a tablelayout01 instance tablelayout = (tablelayout) findviewbyid (R. id. tablelayout01); // all columns are automatically filled with tablelayout spaces. setstretchallcolumns (true); // generate 10 rows and 8 columns of table for (int row = 0; row <10; row ++) {tablerow = new tablerow (this ); for (INT Col = 0; Col <8; Col ++) {// TV is used to display textview TV = new textview (this); TV. settext ("(" + Col + "," + row + ")"); tablerow. addview (TV);} // Add the newly created tablerow to tablelayout. addview (tablerow, new tablelayout. layoutparams (FP, WC ));}}}