首页 > 其他分享 >Android学习|布局——TableLayout 表格布局

Android学习|布局——TableLayout 表格布局

时间:2023-05-10 18:23:29浏览次数:36  
标签:控件 表格 布局 一行 TableLayout Android

一、概述
TableLayout :即表格布局。

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

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

 


如下,设置三个button,其宽度为match_parent、按道应该不占据一行,而却一个button占了一整行

<?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">

    <Button
    android:layout_width="match_parent"/>
    
    <Button
        android:layout_width="match_parent"/>
    
    <Button
        android:layout_width="match_parent"/>
    

</TableLayout>

添加TableRow,使其成表格状

<?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">

    <TableRow>
        <Button
            android:layout_width="match_parent"
            android:text="第一列"/>

        <Button
            android:layout_width="match_parent"
            android:text="第二列"/> 
    </TableRow>

    <TableRow>
        <Button
            android:layout_width="match_parent"
            android:text="第一列"/>

        <Button
            android:layout_width="match_parent"
            android:text="第二列"/>

        <Button
            android:layout_width="match_parent"
            android:text="第三列"/>

        <Button
            android:layout_width="match_parent"
            android:text="第四列"/>

        <Button
            android:layout_width="match_parent"
            android:text="第五列"/>
    </TableRow>


    <TableRow>
        <Button
            android:layout_width="match_parent"
            android:text="第一列"/>
    </TableRow>


</TableLayout>

 

标签:控件,表格,布局,一行,TableLayout,Android
From: https://www.cnblogs.com/sxwgzx23/p/17388883.html

相关文章

  • 布局——TableLayout 表格布局
    常见属性1、android:collapseColumns:设置需要被隐藏的列的序号,从o开始2、android:stretchColumns:设置允许被拉伸的列的列序号,从o开始3、android:shrinkColumns:设置允许被收缩的列的列序号,从o开始4、子控件设置属性a、android:layout_column:显示在第几列b、android:layout......
  • Android string.xml与Excel的互相转换
    Notice使用以下脚本需要安装openpyxl和lxml两个库。string.xml转成Excel文件"""将Androidstring.xml文件中的文本转换成Excel表格并保存到文件。使用方法:pythonandroid_string_to_excel.py-fstrings.xml[-ooutfile_name]-f:要处理的Androidstring.xml文件......
  • 简单瀑布流布局实现
    因为工作上的需要,skidu最近这几周都在折腾瀑布流这玩意。截止到本日志发布日期,主要功能已基本实现,整理一下实现过程以及其中遇到的一些问题吧:)最终目的是实现瀑布流+无限拖拽的页面效果先上局部效果图:====用到的插件====jQuery  jQuery.Masonry 因为skidu本人js玩的并......
  • Android----http请求工具类(转)
    项目中客户端与服务器端采用http请求进行交互,在这里我把http请求的工具类贴出来。该工具类采用的是HttpClients框架,HTTP保存方式有两种选择:一种:整个应用只创建一个HttpClient对象,然后保存在整个程序中去。此情况无法创建多线程中应用。另一种:随时创建HttpClient对象。系统自......
  • Android实现推送方式解决方案 (转1)
    Android实现推送方式解决方案本文介绍在Android中实现推送方式的基础知识及相关解决方案。 1.推送方式基础知识: 当我们开发需要和服务器交互的应用程序时,基本上都需要获取服务器端的数据,比如《地震应急通》就需要及时获取服务器上最新的地震信息。要获取服务器上不定时更新......
  • Android自定义Dialog(zhuang)
    Android自定义Dialog这段时间在做一个项目,需要使用到自定义Dialog,先在网上找了一下资料,发现还是有很多没有讲清楚的,在此给出一个Demo,一来可以方便广大码农,二来也可以方便自己,以备不时之需。。。先来一张图吧,很简单,只有一个Activity,当点击Button的时候就弹出这个自定义的Dialo......
  • Android logcat: Unexpected EOF! 解决办法
     【问题表现】无论使用控制台adb( adblogcat|grep"SilentPlayerManager")还是使用AndroidStudio的logcat,都提示: logcat:UnexpectedEOF!Thismeansthateitherthedeviceshutdown,logdcrashed,orthisinstanceoflogcatwasunabletoreadlogmessagesas......
  • Android Studio中使用断点调试程序
    1.设置断点在希望中断的位置左边label一下,设置一个断点。例如下方图片所示在ActivityResultRegistry类中的第147行设置了一个断点,以及在365行dispatchResult()方法处设置了一个断点。设置好断点后,可以在菜单栏依次点击Run->ViewBreakpoints查看所设置的全部的断点,并进行删减......
  • android.app.BackgroundServiceStartNotAllowedException
    ---------beginningofcrash05-0901:25:24.46521872187EAndroidRuntime:FATALEXCEPTION:main05-0901:25:24.46521872187EAndroidRuntime:Process:com.android.gallery3d,PID:218705-0901:25:24.46521872187EAndroidRuntime:java.lang.Runti......
  • Android TextView 设置超链接、关键字高亮等效果
    之前做TextView关键字高亮效果,使用的是Html.fromHtml(Stringsource)方法,然后通过TextView的setText(CharSequencetext)方法来显示后来测试此方法在部分手机上显示有问题,如Nexus4,华为P6等等。于是乎只能继续寻找别的解决办法了,在这里Mark一下。这里用到了SpannableString类......