Android UI Layout Tablelayout

Source: Internet
Author: User

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> &LT;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" > &lt ; 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

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.