Android之TableLayout表格布局

1、相关属性

1.1、常用属性
    android:collapseColumns  设置需要被隐藏的列的序列号
    android:shrinkColumns 设置允许被收缩的列的序列号
    android:stretchColumns 设置运行被拉伸的列的序列号

    注意: 列号都是从0开始算,设置多个“1,3”,所有列都生效“*”
    android:layout_column = ”2“ 表示跳过第二个
    android:layout_span = ”4“ 表示合并4个单元格

1.2、如何确定行数和列数
    !如何直接往TableLayout中添加组件的话,那个这个组件将占满一行
    !如何想一行有多个组件,就添加一个TableRow的容器,把组件放进去
    !tablerow中组件个数决定列数,列的宽度由最宽的单元格决定
    !TableRow的宽度是默认的不能修改,高度可以自定义
    !整个表格布局的宽度取决于父容器的宽度

2、示例

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".LoginActivity"
    android:stretchColumns="0,3"
    android:gravity="center_vertical"
    android:background="#66ff66">

    <TableRow>
        <TextView />
        <TextView
            android:layout_height="wrap_content"
            android:text="用户名:"/>
        <EditText
            android:layout_height="wrap_content"
            />
        <TextView />
    </TableRow>

    <TableRow>
        <TextView />
        <TextView
            android:layout_height="wrap_content"
            android:text="密  码"/>
        <EditText
            android:layout_height="wrap_content"
            android:minWidth="200dp"/>
        <TextView />
    </TableRow>

    <TableRow>
        <TextView />

        <Button
            android:layout_height="wrap_content"
            android:text="登录"/>
        <Button
            android:layout_width="60dp"
            android:text="退出"/>
        <TextView />
    </TableRow>

</TableLayout>

效果图

 

转载于:https://www.cnblogs.com/xianfeng-zhang/p/7991696.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值