Learning notes for Android: table layout

Source: Internet
Author: User

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 ));}}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.