当前位置:首页 > 嵌入式 > 嵌入式软件
[导读] 三表格布局(TableLayout)以及重要属性TableLayout跟TableRow 是一组搭配应用的布局,TableLayout置底,TableRow在TableLayout的上方,而Button、TextView等控件就在Table

 三表格布局(TableLayout)以及重要属性

TableLayout跟TableRow 是一组搭配应用的布局,TableLayout置底,TableRow在TableLayout的上方,而Button、TextView等控件就在TableRow之上,别的,TableLayout之上也可以零丁放控件。TableLayout是一个应用错杂的布局,最简单的用法就仅仅是拖沓控件做出个界面,但实际上,会经常在代码里应用TableLayout,例如做出表格的结果。本文首要介绍TableLayout的根蒂根基应用办法。

重要的几个属性如下:

1.android:collapseColumns://隐藏指定的列

①设置 TableLayout 内的 TableRow 中需要隐藏的列的列索引,多个用“,”隔开

②以第0行为序,隐藏指定的列:把android:collapseColumns=0,3 意思是把第0和第3列隐藏

2.android:shrinkColumns://收缩指定的列以适合屏幕、不会挤出屏幕 ① 设置 TableLayout 内的 TableRow 中需要拉伸(该列会拉伸到所有可用空间)的列的列索引,多列个用“,”隔开(多列 每列填充空隙大小一样)

②以第0行为序,自动延伸指定的列填充可用部分: 当LayoutRow里面的控件还没有布满布局时,shrinkColumns不起作用。

③设置了shrinkColumns=1,4,布局完全没有改变,因为LayoutRow里面还剩足够的空间。当LayoutRow布满控件时,设置了shrinkColumns=2,5,则控件自动向垂直方向填充空间

3.android:stretchColumns://尽量把指定的列表填充空白部分

①设置 TableLayout 内的 TableRow 中需要收缩(为了使其他列不会被挤到屏幕 外,此列会自动收缩)的列的列索引,多个用“,”隔开

② 以第0行为序,尽量把指定的列填充空白部分:设置stretchColumns=2,5,第1,4列被尽量填充同时向右填充,直到2,5被压挤到最后边)。

补充:

①表格布局的子对象不能指定 layout_width 属性.宽度永远是 MATCH_PARENT。

②不过子对象可以定义 layout_height 属性;其默认值是WRAP_CONTENT. 如果子对象是 TableRow,其高度永远是 WRAP_CONTENT。

实例:

001 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
002     xmlns:tools="http://schemas.android.com/tools"
003     android:layout_width="match_parent"
004     android:layout_height="match_parent"
005     android:orientation="vertical"
006     tools:context=".AndroidTableLayoutActivity" >
007  
008     <!-- 定义第一个表格,指定第2列允许收缩,第3列允许拉伸 -->
009  
010     <TableLayout
011         android:id="@+id/tablelayout01"
012         android:layout_width="match_parent"
013         android:layout_height="wrap_content"
014         android:shrinkColumns="1"
015         android:stretchColumns="2" >
016  
017         <!-- 直接添加按钮,自己占用一行 -->
018  
019         <Button
020             android:id="@+id/btn01"
021             android:layout_width="wrap_content"
022             android:layout_height="wrap_content"
023             android:text="独自一行" >
024         </Button>
025  
026         <TableRow>
027  
028             <Button
029                 android:id="@+id/btn02"
030                 android:layout_width="wrap_content"
031                 android:layout_height="wrap_content"
032                 android:text="普通" >
033             </Button>
034  
035             <Button
036                 android:id="@+id/btn03"
037                 android:layout_width="wrap_content"
038                 android:layout_height="wrap_content"
039                 android:text="允许被收缩允许被收缩允许被收缩允许被收缩" >
040             </Button>
041  
042             <Button
043                 android:id="@+id/btn04"
044                 android:layout_width="wrap_content"
045                 android:layout_height="wrap_content"
046                 android:text="允许被拉伸允许被拉伸允许被拉伸" >
047             </Button>
048         </TableRow>
049     </TableLayout>
050     <!-- 定义第2个表格,指定第2列隐藏 -->
051  
052     <TableLayout
053         android:id="@+id/tablelayout02"
054         android:layout_width="match_parent"
055         android:layout_height="wrap_content"
056         android:collapseColumns="1" >
057  
058         <TableRow>
059  
060             <Button
061                 android:id="@+id/btn05"
062                 android:layout_width="wrap_content"
063                 android:layout_height="wrap_content"
064                 android:text="普通" >
065             </Button>
066  
067             <Button
068                 android:id="@+id/btn06"
069                 android:layout_width="wrap_content"
070                 android:layout_height="wrap_content"
071                 android:text="被隐藏列" >
072             </Button>
073  
074             <Button
075                 android:id="@+id/btn07"
076                 android:layout_width="wrap_content"
077                 android:layout_height="wrap_content"
078                 android:text="允许被拉伸" >
079             </Button>
080         </TableRow>
081     </TableLayout>
082     <!-- 定义第3个表格,指定第2列填满空白 -->
083  
084     <TableLayout
085         android:id="@+id/tablelayout03"
086         android:layout_width="match_parent"
087         android:layout_height="wrap_content"
088         android:stretchColumns="1" >
089  
090         <TableRow>
091  
092             <Button
093                 android:id="@+id/btn08"
094                 android:layout_width="wrap_content"
095                 android:layout_height="wrap_content"
096                 android:text="普通" >
097             </Button>
098  
099             <Button
100                 android:id="@+id/btn09"
101                 android:layout_width="wrap_content"
102                 android:layout_height="wrap_content"
103                 android:text="填满剩余空白" >
104             </Button>
105         </TableRow>
106     </TableLayout>
107     <!-- 定义第3个表格,指定第2列横跨2列 -->
108  
109     <TableLayout
110         android:id="@+id/tablelayout04"
111         android:layout_width="match_parent"
112         android:layout_height="wrap_content" >
113  
114         <TableRow>
115  
116             <Button
117                 android:id="@+id/btn10"
118                 android:layout_width="wrap_content"
119                 android:layout_height="wrap_content"
120                 android:text="普通" >
121             </Button>
122  
123             <Button
124                 android:id="@+id/btn11"
125                 android:layout_width="wrap_content"
126                 android:layout_height="wrap_content"
127                 android:layout_column="2"
128                 android:text="填满剩余空白" >
129             </Button>
130         </TableRow>
131     </TableLayout>
132  
133 </LinearLayout>
本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除。
换一批
延伸阅读

武汉2025年9月9日 /美通社/ -- 7月24日,2025慧聪跨业品牌巡展——湖北•武汉站在武汉中南花园酒店隆重举办!本次巡展由慧聪安防网、慧聪物联网、慧聪音响灯光网、慧聪LED屏网、慧聪教育网联合主办,吸引了安防、...

关键字: AI 希捷 BSP 平板

上海2025年9月9日 /美通社/ -- 9月8日,移远通信宣布,其自研蓝牙协议栈DynaBlue率先通过蓝牙技术联盟(SIG)BQB 6.1标准认证。作为移远深耕短距离通信...

关键字: 蓝牙协议栈 移远通信 COM BSP

上海2025年9月9日 /美通社/ -- 为全面落实党中央、国务院和上海市委、市政府关于加快发展人力资源服务业的决策部署,更好发挥人力资源服务业赋能百业作用,8月29日,以"AI智领 HR智链 静候你来&quo...

关键字: 智能体 AI BSP 人工智能

北京2025年9月8日 /美通社/ -- 近日,易生支付与一汽出行达成合作,为其自主研发的"旗驭车管"车辆运营管理平台提供全流程支付通道及技术支持。此次合作不仅提升了平台对百余家企业客户的运营管理效率...

关键字: 一汽 智能化 BSP SAAS

深圳2025年9月8日 /美通社/ -- 晶泰科技(2228.HK)今日宣布,由其助力智擎生技制药(PharmaEngine, Inc.)发现的新一代PRMT5抑制剂PEP0...

关键字: 泰科 AI MT BSP

上海2025年9月5日 /美通社/ -- 由上海市经济和信息化委员会、上海市发展和改革委员会、上海市商务委员会、上海市教育委员会、上海市科学技术委员会指导,东浩兰生(集团)有限公司主办,东浩兰生会展集团上海工业商务展览有...

关键字: 电子 BSP 芯片 自动驾驶

推进卓越制造,扩大产能并优化布局 苏州2025年9月5日 /美通社/ -- 耐世特汽车系统与苏州工业园区管委会正式签署备忘录,以设立耐世特亚太总部苏州智能制造项目。...

关键字: 智能制造 BSP 汽车系统 线控

慕尼黑和北京2025年9月4日 /美通社/ -- 宝马集团宣布,新世代首款量产车型BMW iX3将于9月5日全球首发,9月8日震撼亮相慕尼黑车展。中国专属版车型也将在年内与大家见面,2026年在国内投产。 宝马集团董事...

关键字: 宝马 慕尼黑 BSP 数字化

北京2025年9月4日 /美通社/ -- 在全球新一轮科技革命与产业变革的澎湃浪潮中,人工智能作为引领创新的核心驱动力,正以前所未有的深度与广度重塑各行业发展格局。体育领域深度融入科技变革浪潮,驶入数字化、智能化转型快车...

关键字: 人工智能 智能体 AI BSP

上海2025年9月2日 /美通社/ -- 近日,由 ABB、Moxa(摩莎科技)等八家企业在上海联合发起并成功举办"2025 Ethernet-APL 技术应用发展大会"。会议以"破界•融合...

关键字: ETHERNET 智能未来 BSP 工业通信
关闭