zoukankan      html  css  js  c++  java
  • Android UI布局之TableLayout

    从字面上了解TableLayout是一种表格式的布局。这样的布局会把包括的元素以行和列的形式进行排列。表格的列数为每一行的最大列数。当然表格里边的单元格是能够为空的。

    实例:LayoutDemo
    执行效果:


    代码清单:
    布局文件: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="用户名称:"
            />
            <EditText 
                android:id="@+id/username"
                android:padding="3dip"
                android:scrollHorizontally="true"
            />
        </TableRow>
        <TableRow>
            <TextView
                android:gravity="right"
                android:textStyle="bold"
                android:padding="3dip"
                android:text="用户密码:"
            />
    
            <EditText 
                android:id="@+id/password"
                android:padding="3dip"
                android:password="true"
            />
        </TableRow>
        <TableRow android:gravity="right">
            <Button
                android:id="@+id/cancel"
                android:text="取消" 
            />
            <Button
                android:id="@+id/login"
                android:text="登录" 
            />
        </TableRow>
    </TableLayout>
    在上面的布局代码中一共同拥有3行。即3个TableRow,每个TableRow里边都有两个单元格。


    TableLayout标签定义了一个表格布局(TableLayout).
    TableRow标签定义了表格布局里边的一行。

    每一行里边能够自由的加入一些组件。比方在上边我们主要加入了button组件和编辑框组件。

    Java源码文件: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);
        }
    }
    



  • 相关阅读:
    git 管理
    SVN 管理
    为什么要做静态库
    Sqlite3
    CocoaPod
    内存管理
    readline的用法
    join合并字符串时使用生成器表达式
    pandas DataFrame数据转为list
    Jenkins自动化CI CD流水线之4--Master-Slave架构
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/6917243.html
Copyright © 2011-2022 走看看