Android learning-layout tablelayout table layout

Source: Internet
Author: User

Table layout contains a series of tablerow objects for defining rows (you can also use other sub-objects, which will be explained later ). The table layout does not display table lines for its rows, columns, and cells. Each row can contain more than 0 (including 0) cells, and each cell can set a view object. Like a row that contains many cells, a table contains many columns. Cells in a table can be empty. cells can span columns as HTML does.

The column width is determined by the widest cell in all rows of the column. however, you can use the setcolumnshrinkable () method or the setcolumnstretchable () method to mark whether certain columns can be shrunk or stretched. if it is marked as condensed, the column width can be reduced to make the table fit the container size. If it is marked as extensible, the column width can be stretched to occupy extra space. The total width of a table is determined by its parent container. It is important to remember that columns can be stretched and shrunk simultaneously. It is useful when the column width can be adjusted to occupy available space, but it cannot exceed the limit. Finally, you can hide the column by calling setcolumncollapsed.

The layout_width attribute cannot be specified for sub-objects in table layout. The width is always match_parent. However, the layout_height attribute can be defined for sub-objects. The default value is wrap_content. If the sub-object is tablerow, its height will always be wrap_content.

The following example shows how to design the interface...

. Xml file

<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" xmlns: Tools = "http://schemas.android.com/tools" Android: Orientation = "vertical" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" tools: context = ". twohousetansactivity "> <tablelayout Android: layout_width =" wrap_content "Android: layout_height =" wrap_content "Android: layout_alignparentleft =" true "Android: true =" Android: gravity = "Left"> <tablerow Android: Id = "@ + ID/tablerow1" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content"> <textview Android: id = "@ + ID/tvprice" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "price"/> <edittext Android: id = "@ + ID/etprice" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: textcolor = "#606060" Android: textsize = "16px" Android: width = "90dp"> </edittext> <textview Android: Id = "@ + ID/tvbuildarea" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: TEXT = "building area"/> <edittext Android: Id = "@ + ID/etbuildarea" Android: layout_width = "70dp" Android: layout_height = "wrap_content" Android: width = "85dp"/> </tablerow> <tablerow Android: Id = "@ + ID/tablerow2" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content"> <textview Android: Id = "@ + ID/tvmf" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: TEXT = "buyer"/> <textview Android: Id = "@ + ID/tvmfd" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: width = "90dp" Android: text = ""/> <textview Android: Id = "@ + ID/tvmf" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "seller"/> </tablerow> <textview Android: Id = "@ + ID/tvqs" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = ""/> <edittext Android: Id = "@ + ID/etqs" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: layout_alignparenttop = "true" Android: width = "80dp"/> <textview Android: id = "@ + ID/tvyes" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = ""/> <edittext Android: id = "@ + ID/etyes" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: width = "60dp"/> </tablerow> <textview Android: Id = "@ + ID/tvmjyyhs" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "Stamp Duty"/> <edittext Android: Id = "@ + ID/etmjyyhs" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: width = "90dp"/> <textview Android: Id = "@ + ID/tvmijyyhs" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "Stamp Duty"/> <edittext Android: Id = "@ + ID/etmijyyhs" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: width = "60dp"/> </tablerow> <textview Android: Id = "@ + ID/tvmjyfws" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "transaction service tax"/> <edittext Android: Id = "@ + ID/etmjyfws" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: width = "80dp"/> <textview Android: Id = "@ + ID/tvmijyfws" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "transaction service tax"/> <edittext Android: Id = "@ + ID/etmijyfws" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: width = "60dp"/> </tablerow> <textview Android: id = "@ + ID/tvmcqdjf" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "Property Registration Fee"/> <edittext Android: id = "@ + ID/etmcqdjf" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: width = "80dp"/> <textview Android: id = "@ + ID/tvmicqdjf" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "Personal Income Tax"/> <edittext Android: id = "@ + ID/etmicqdjf" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: width = "60dp"/> </tablerow> <textview Android: Id = "@ + ID/tvtotal" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "Total"/> <edittext Android: Id = "@ + ID/ettotalprice" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: width = "95dp"/> <textview Android: Id = "@ + ID/tvmtotal" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "Total"/> <edittext Android: Id = "@ + ID/etmtotalprice" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: width = "70dp"/> </tablerow> <button Android: Id = "@ + ID/btncal" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "computing"/> </tablerow> </tablelayout> </linearlayout>

Related Article

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.