Android UI layout: TableLayout and androidtablelayout

Source: Internet
Author: User

Android UI layout: TableLayout and androidtablelayout
Literally, TableLayout is a table layout. This layout will arrange the contained elements in the form of rows and columns. The number of columns in a table is the maximum number of columns in each row. Of course, the cells in the table can be empty.

Instance: LayoutDemo
Running effect:


Code List:
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> <TextView android: gravity = "right" android: textStyle = "bold" android: padding = "3dip" android: text = "User name:"/> <EditText android: id = "@ + id/username" android: padding = "3dip" android: scrollHorizontally = "true"/> </TableRow> <TextView android: gravity = "right" android: textStyle = "bold" android: padding = "3dip" android: 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 = "cancel"/> <Button android: id = "@ + id/login" android: text = "login"/> </TableRow> </TableLayout>
In the preceding layout code, there are three rows, namely three TableRow. Each TableRow contains two cells.
The TableLayout label defines a table layout (TableLayout ).
The TableRow label defines a row in the table layout. Some components can be freely added to each line. For example, we have added the button component and the edit box component.

Java source code 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);    }}




What should I do if the layout of android tablelayout is insufficient for the screen ???

How to set the height of tablelayout, whether to use android: layout_height = "fill_parent ";
In addition, whether tablelayout is embedded in LinearLayout. if so, whether the height of LinearLayout is also android: layout_height = "fill_parent ".
As long as the height of tablelayout is set to full parent control, the parent control is also set to tablelayout to be full screen.
Then, some of your TableRow does not use android: layout_weight = "1". Add the weight.

TableLayout layout in android

<TableRow>
<Button android: id = "@ + id/btndel" android: layout_width = "100dp" android: layout_height = "wrap_content" android: layout_weight = "1" android: text = "delete"/>
<Button android: id = "@ + id/btnupdate" android: layout_width = "50dp" android: layout_height = "wrap_content" android: layout_weight = "1" android: text = "Update"/>
<Button android: id = "@ + id/btnupdate" android: layout_width = "70dp" android: layout_height = "wrap_content" android: layout_weight = "1" android: text = "Update"/> </TableRow>
Are you talking about this situation?



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.