Android常用布局之TableLayout(表格布局)

这篇具有很好参考价值的文章主要介绍了Android常用布局之TableLayout(表格布局)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

概述:

TableLayout(即表格布局)

当TableLayout下面写控件、则控件占据一行的大小。(自适应一行,不留空白)

但是,想要多个组件占据一行,则配合TableRow实现

TableLayout继承自LinearLayout, 因此它完全支持LinearLayout所支持的属性,此外,它还有其他的常用属性。

属性名称 功能描述
android:stretchColumns 设置可被拉伸的列。如:android:stretchColumns-~0”, 表示第1列可被拉伸
android:shrinkColumns 设置可被收缩的列,如:android:shrinkColumns=“1. 2”, 表示2, 3列可收编
android:collapseColumns

设置可被隐藏的列,如:android:collapseColumns=~0”, 表示第1列可被隐藏


对控件的属性有

android:layout_span 设置该控件占据儿行,默认为1行
android:layout_column 设置该控件显示的位置,如 android:layout_column-"l”表示在第2个位置显示

实例

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".TableLayoutActivity">
    <!--    整体采用表格布局的方式-->
    <TextView
        android:id="@+id/text1"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:text="表格布局"
        android:gravity="center"
        android:textSize="50dp"
        />
<!--    默认一个控件为一行-->
    <Button
        android:layout_height="wrap_content"
        android:background="@color/teal_700">
    </Button>
    <Button
        android:layout_height="wrap_content"
        android:background="@color/purple_200">
    </Button>
    <TextView
        android:id="@+id/text2"
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:text="TableRow"
        android:gravity="center"
        android:textSize="30dp"
        />
    <TableLayout
        android:layout_width="wrap_content"
        android:layout_height="400px"
        android:stretchColumns="2"
        >
    <TableRow>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="0"
            android:text="1"
            ></Button>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="1"
            android:text="2"
            ></Button>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="2"
            android:text="3"
            ></Button>
    </TableRow>
    <TableRow>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="1"
            android:text="4"
            ></Button>
    </TableRow>
    <TableRow>
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="2"
                android:text="5"
                ></Button>
    </TableRow>
    </TableLayout>
    <TextView
        android:id="@+id/text3"
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:text="隐藏第一列"
        android:gravity="center"
        android:textSize="30dp"
        />
    <TableLayout
        android:layout_width="wrap_content"
        android:layout_height="400px"
        android:collapseColumns="0"
        android:stretchColumns="2"
        >
        <TableRow>
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="0"
                android:text="1"
                ></Button>
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="1"
                android:text="2"
                ></Button>
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="2"
                android:text="3"
                ></Button>
        </TableRow>
        <TableRow>
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="1"
                android:text="4"
                ></Button>
        </TableRow>
        <TableRow>
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="2"
                android:text="5"
                ></Button>
        </TableRow>
    </TableLayout>
</TableLayout>

实现效果:

Android常用布局之TableLayout(表格布局)

 表格布局用的不是很多,但是我们也需要学习!文章来源地址https://www.toymoban.com/news/detail-406878.html

到了这里,关于Android常用布局之TableLayout(表格布局)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Android开发—布局LinearLayout,布局RelativeLayout常见属性根据父容器定位,兄弟组件定位,FrameLayout帧布局的绘制原理是,TableLayout

    1. orientation  布局中组件的排列方式 2. gravity  控制组件所包含的子元素的对齐方式,可多个组合 3. layout _ gravity  控制该组件在父容器里的对其方式 4. background  为该组件设置一个背景图片,或者是直接用颜色覆盖 5. divider  分割线 6. showDividers 设置分割线所在的位置,

    2024年02月03日
    浏览(34)
  • 布局设计和实现:计算器UI【TableLayout、GridLayout】

    根据自己的需求输入其他信息 填写完成后,点击 Finish 即可 在 res/layout 文件夹中的XML文件中创建UI界面。在这个XML文件中,您可以使用TableLayout来设计计算器界面。 2.1 创建layout文件夹 但是默认创建出来的项目并不会包含 layout 布局文件夹,因此需要我们自行创建 在 res 目录内

    2024年02月04日
    浏览(30)
  • Android常用布局之FrameLayout(帧布局)

    FrameLayout(帧布局)可以说是六大布局中最为简单的一个布局,这个布局直接在屏幕上开辟出一块空白的区域,当我们往里面添加控件的时候,会默认把他们放到这块区域的 左上角, 而这种布局方式却没有任何的定位方式,所以它应用的场景并不多;帧布局的大小由控件中最大的子控件

    2023年04月10日
    浏览(79)
  • Android基础学习笔记8:常用布局 - 线性布局

    能说出安卓界面元素层次 能说出安卓常用的布局 能说出线性布局常用的属性 能利用线性布局实现简单的界面设计 能利用线性布局嵌套实现比较复杂的界面 应用界面包含用户可查看并与之交互的所有内容。安卓提供丰富多样的预置 UI 组件,例如结构化布局对象和 UI 控件,您

    2024年02月05日
    浏览(36)
  • Android学习笔记 - 常用的布局

    Android中有六种的布局方式,分别是:LinearLayout(线性布局)、RelativeLayout(相对布局)、TableLayout(表格布局)、FrameLayout(帧布局)、AbsoluteLayout(绝对布局)、GridLayout(网格布局)。在开发中,我们用的最多的就是线性布局和相对布局。 线性布局是我们在开发中用的最多的一种布局方式。

    2024年02月04日
    浏览(31)
  • Android的 AlertDialog自定义布局与常用布局用法(弹窗)

    1.直接上效果图,看看是不是你们想要的效果图 2.主活动MainActivity2的代码如下

    2024年02月12日
    浏览(30)
  • Android基础学习常用UI布局

    XML 常用属性 布局特点:放主要提供控件水平或者垂直排列的模型,每个子组件都是以垂直或水平的方式来线性排布.(默认是垂直) 基本属性 布局特点:为某一个组件为参照物,来定位下一个组件的位置的布局方式。 常用属性: 如何确定列数与行数 直接往TableLayout中添加组件

    2024年02月16日
    浏览(29)
  • 【Android Studio】常用布局 --- 滚动视图ScrollView

    问题引入 :手机屏幕的显示空间有限,常常需要上下滑动或左右滑动才能拉出其余页面内容,可惜一般的布局节点 都不支持自行滚动,这时就要借助滚动视图了。与线性布局类似,滚动视图也分为垂直方向和水平方向 两类,其中垂直滚动视图名为ScrollView,水平滚动视图名为

    2023年04月11日
    浏览(35)
  • Android布局和控件:创建用户界面的XML布局文件和常用UI控件详解

    在Android应用开发中,创建用户界面是一个重要的任务。通过使用XML布局文件和常用的UI控件,开发人员可以设计和构建出吸引人且功能丰富的应用界面。本文将详细介绍如何使用XML布局文件来创建Android应用的用户界面,并深入探讨一些常用UI控件的属性和用法。 XML布局文件是

    2024年02月17日
    浏览(34)
  • Android Studio入门之常用布局的讲解以及实战(附源码 超详细必看)(包括线性布局、权重布局、相对布局、网格布局、滚动视图 )

    运行有问题或需要源码请点赞关注收藏后评论区留言 顾名思义,线性布局像是用一根线把它的内部视图串起来,故而内部视图之间的排列顺序是固定的,要么从左到右,要么从上到下排列。通过属性android:orientation区分两种方向 下面通过一个实例讲解 效果如下  activity_linea

    2023年04月20日
    浏览(38)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包