美文网首页
2.2.4 表格布局

2.2.4 表格布局

作者: EDU_MJ | 来源:发表于2017-10-26 19:37 被阅读0次

表格布局的概念

表格布局(TableLayout)是以表格形式排列控件的,通过行和列将界面划分为多个单元格,每个单元格都可以添加控件。

表格布局需要和TableRow配合使用,每一行都由TableRow对象组成,因此TableRow的数量决定表格的行数。
而表格的列数是由包含最多控件的TableRow决定的,例如第1个TableRow有两个控件,第2个TableRow有三个控件,则表格列数为3。

基本属性


1 TableLayout属性

属性 含义
android:layout_stretchColumns 设置被拉伸的列,从0开始
android:layout_shrinkColumns 设置被收缩的列,从0开始
android:layout_collapsecolumns 设置该列被隐藏,从0开始

例如:设置一个两行三列的表格,第三列为拉伸列,当三列不能排完一行时,第三列进行拉伸。

<?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="2"
    >
<TableRow>
    <Button
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="1"/>
    <Button
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="2"/>
    <Button
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="3"/>

</TableRow>
    <TableRow>
        <Button
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="4"/>
        <Button
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="5"
            />
        <Button
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="6"
            />
    </TableRow>
</TableLayout>

2 TableLayout控件属性

属性 含义
android:layout_column 设置单元格显示位置,从0开始
android:layout_span 设置单元格所占列数

例如:第五个按钮占两列,第六个按钮处于第二列

<?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="2"
    >
<TableRow>
    <Button
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="1"/>
    <Button
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="2"/>
    <Button
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="3"/>

</TableRow>
    <TableRow>
        <Button
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="4"/>
        <Button
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="5"
            android:layout_span="2"
            />
    </TableRow>
    <TableRow>
        <Button
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="6"
            android:layout_column="1"
            />
    </TableRow>
</TableLayout>

相关文章

  • 2.2.4 表格布局

    表格布局的概念 表格布局(TableLayout)是以表格形式排列控件的,通过行和列将界面划分为多个单元格,每个单...

  • 2019-03-15

    实验内容:关于线性布局、约束布局及表格布局的使用 主要代码: 主界面: 线性布局: 约束布局: 表格布局: 截图:...

  • DIV内容垂直居中

    《虽然Div布局已经基本上取代了表格布局,但表格布局和Div布局仍然各有千秋,互有长处。比如表格布局中的垂直居中就...

  • Android之6大布局

    LineLayout (线性布局) RelativeLayout(相对布局) TableLayout(表格布局) ...

  • 2 布局

    LinearLayout(线性布局) RelativeLayout(相对布局) TableLayout(表格布局)...

  • Tailwind Table

    表格样式工具类 表格布局table layout CSS中table-layout属性用于设置表格布局的类型,即用...

  • TableLayout 表格布局管理器

    表格布局与常见的表格类似,以行列的形式来管理放入其中的组件,表格布局使用TableLayout的形式进行定义。表格...

  • TableLayout-表格布局

    表格布局让我想到了GridLayout(网格布局),TableLayout为表格布局,也是本章的重点所在。 Tab...

  • Android控件<第十三篇>:TableLayout-表格布局

    表格布局让我想到了GridLayout(网格布局),TableLayout为表格布局,也是本章的重点所在。 Tab...

  • 布局-表格布局

    1.布局概述 MisShop中,通过布局区域来实现页面元素的排放。和通常的html规则相同,MisShop支持 表...

网友评论

      本文标题:2.2.4 表格布局

      本文链接:https://www.haomeiwen.com/subject/uttlpxtx.html