tablelayout是一种Android UI布局,继承自linearLayout,
一行中添加单个组件:直接在TableLayout中添加组件
一行中添加多个组件:使用TableRow,将组件写在TableRow下
TableLayout 中有多少个组件,就有多少行    (一个tablerow一行,一个单独的组件也一行!多少列则是看tableRow中 的组件个数,组件最多的就是TableLayout的列数)

常用属性:
tableLayout下
android:collapseColumns:设置需要被隐藏的列的序号
android:shrinkColumns:设置允许被收缩的列的列序号
android:stretchColumns:设置运行被拉伸的列的列序号(可沾满剩余空间)
android:layout_column="2":表示的就是跳过第二个,直接显示到第三个格子处,从1开始算的!
android:layout_span="4":表示合并4个单元格,也就说这个组件占4个单元格
TableRow的子控件的主要属性:
android:layout_column=”1” 该控件显示在第1列
android:layout_span=”2” 该控件占据2

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

<TableLayout
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:background="@color/pink">
        <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="啥都没做"/>
        <TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="1-1"/>
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1-2"/>
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1-3"/>
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="1-4"/>
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1-5"/>
        </TableRow>
    </TableLayout>
    
    <TableLayout
            android:background="@color/hui"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:collapseColumns="2">
        <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="属性1:android:collapseColumns:需要被隐藏的列序号"/>
        <TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1-1"/>
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1-2"/>
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1-3"/>
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1-4"/>
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1-5"/>
        </TableRow>
    </TableLayout>

<TableLayout
            android:background="@color/blue"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:shrinkColumns="2">
        <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="属性2:android:shrinkColumns:允许被收缩的列序号"/>
        <TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1-1"/>
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1-2"/>
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1-3"/>
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1-4"/>
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1-5"/>
        </TableRow>
    </TableLayout>

<TableLayout
            android:background="@color/green"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:stretchColumns="1">
        <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="属性3:android:stretchColumns:允许被拉伸的列序号"/>
        <TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1-1"/>
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1-2"/>
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1-3"/>
        </TableRow>
    </TableLayout>

<TableLayout
            android:background="@color/yellow"
            android:layout_width="match_parent"
            android:layout_height="300dp">
        <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="啥都没做"/>
        <TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1-1"/>
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1-2"/>
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1-3"/>
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1-4"/>
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1-5"/>
        </TableRow>
       <Button
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:text="子控件属性:android:layout_column=”1”控件显示在第1列"/>
        <TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="2-1"/>
            <Button
                    android:layout_column="3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="2-2"/>
            <Button

android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="2-3"/>
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="2-4"/>
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="2-5"/>
        </TableRow>
       <Button
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:text="子控件属性:android:layout_span=”2” 该控件占据2列"/>
        <TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="3-1"/>
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="3-2"/>
            <Button
                    android:layout_span="2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="3-3"/>
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="3-4"/>
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="3-5"/>
        </TableRow>
        <TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="4-1"/>
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="4-2"/>
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="4-3"/>
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="4-4"/>
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="4-5"/>
        </TableRow>
    </TableLayout>
</LinearLayout>

Android TableLayout记相关推荐

  1. Android TableLayout

    Android TableLayout is used to create grids on the screen. It's one of the ViewGroup classes, which ...

  2. android标签table,详解Android TableLayout表格布局

    表格布局的标签是TableLayout,TableLayout继承了LinearLayout.所以它依然是一个线性布局. 前言: 1.TableLayout简介 2.TableLayout行列数的确定 ...

  3. [Android] TableLayout

    public class TableLayout extends LinearLayout 查过文档,整理下要点: 一个 TableLayout 包含一些 TableRow 对象,每个对象代表一行.除 ...

  4. Android TableLayout 常用的属性介绍及演示

    TableLayout经常用的属性是: 1.android:collapseColumns:以第0行为序,隐藏指定的列:把android:collapseColumns=0,2 意思是把第0和第2列隐 ...

  5. Android—TableLayout自定义表格

    最近的一个项目中,需要用的表格,由于平时很少用到表格,所以,就准备到网上搜搜,发现可参考的很少,加上,自己也想多了解点TableLayout 布局,所欲就打算自己动手来实现自己需要的表格.先看看需求吧 ...

  6. android tablelayout 点击,Android Design之TableLayout选项卡

    Android Design之TableLayout选项卡 Android Design之TableLayout选项卡 先上效果图: 1.导入Design包(所有Design下的控件,第一步都是倒包) ...

  7. android 支付宝 记账本,支付宝app中的记账本该怎么记账?

    对于一般人而言,生活节奏的变快使得记忆越来越不清晰,而每月的花销怎么也算不清,明明没有买什么东西,没有怎么出去玩,生活费怎么就没了呢?你是否有这样的经历,或许曾经想过记账,但是没有坚持下来.而网上钱包 ...

  8. android tablelayout 多行,android – 自定义TableLayout,行中有多个TextView

    我想用这样的行来创建自定义TableLayout: 电视用于TextView,即我想在行中添加11个TextView: 每行以标题开头,然后我添加5对TextView,这样表格行就像屏幕一样宽. 这是 ...

  9. android - TableLayout之android:collapseColumns ,android:shrinkColumns 和stretchColumns

    TableLayout经常用的属性是: android:collapseColumns:以第0行为序,隐藏指定的列: android:collapseColumns该属性为空时,如下图: 把andro ...

最新文章

  1. 南京大学人工智能学院院长周志华:培养有源头创新力的人才!
  2. 如何为WCF应用添加X509证书和安全验证
  3. (Hook)SetWindowsHookEx和UnhookWindowsHookEx
  4. 使用 LxRunOffine 迁移 WSL Ubuntu安装目录
  5. 现实地形导入UE4全流程
  6. Linux文件系统选择
  7. 鲲鹏性能优化十板斧(三)——网络子系统性能调优
  8. python预测发展趋势_Python预测算法哪家强?权游龙妈是生还是凉凉?
  9. java spring orm jbpm_spring整合jbpm4
  10. NameError: name 'reload' is not defined等python版本问题解决方案
  11. pom.xml中添加oracle数据库驱动包报错: Missing artifact com.oracle:ojdbc14:jar:10.2.0.4.0
  12. Java商店管理系统
  13. win10用一会就蓝屏重启_win10蓝屏memory management原因以及解决方法
  14. 安装RHEL 7(Centos7类同)
  15. 十进制与R进制之间的转换
  16. arch linux yaourt arm,在ARM设备(树莓派、香蕉派)上为Arch Linux配置yaourt
  17. webstorm 风扇一直响_在 Webstorm 伤透我的心后,我决定尝试 VS Code
  18. Python实现桌面宠物
  19. 国外搜索引擎+视频网站
  20. GEE(python)使用GPM降水数据进行趋势分析,MK检验等

热门文章

  1. CreateProcess的用法
  2. 数据科学家技能树(中文翻译版)
  3. win10怎么显示文件后缀名
  4. JS Array.slice 截取数组的实现方法
  5. redhat各版本和下载地址
  6. 程序设计方法学-python
  7. python2和python3的区别
  8. traceroute出现*的分析
  9. 2021-10-26 2021年B站1024安全攻防题第一题(加密解密)
  10. BUUCTF NewStarCTF 公开赛赛道Week3 Writeup