Android布局之TableLayout

Android布局之TableLayout

转:http://www.iteye.com/topic/1114402

 

TableLayout:表格布局

 TableLayout布局是LinearLayout的扩展,以行和列的形式组织其子控件。与HTML中得Table相似。每一个TableRow元素代表一行TableRow中包含几个控件代表几列。尽管使用TableRow来填充TableLayout是最常见的模式,但是该布局中可以放置任何子控件。需要指出的是TableLayout的子控件不能指定android:layout_width="wrap_content",它们被强制设定为fill_parent。但是可以设置高度。还有两个不太好理解的属性的说一下,androidstretchColums 此属性指要被拉伸的列。取值可以单个列的索引也可以是一组列的索引值。例如:如果一行有三列。stretchColums="1" 这表示拉伸第二列填充剩余空间。android:layout_column="1" 这个属性指定子控件放置在哪一列上。例如

<TextView   android:layout_column="1"   android:text="Open..."   android:padding="3dip" /> 指该控放置在第二列。上图:

 

<?xml version="1.0" encoding="utf-8"?>
<!--   
android:stretchColumns="1"是设置 TableLayout所有行的第二列为拉伸列。   
也就是说如果每行都有三列的话,剩余的空间由第二列补齐   
-->  
<!-- 最外层包裹一个滚动条 --> 
<ScrollView 
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content">
	<TableLayout 
	    android:layout_width="fill_parent"
	    android:layout_height="fill_parent"
	    android:stretchColumns="1">
	    <TableRow>
	        <View
	        	android:layout_height="80dp"
	        	android:layout_width="250dp"
	        	android:background="#D6D6D6"
	        />
	        <TextView 
	        	android:layout_height="80dp"
	        	android:text="#D6D6D6"
				android:gravity="center"/>
	    </TableRow>
	    <!-- 此处的View控件充当着一个分割条的作用 -->
		<View
			android:layout_height="2dip"
	        android:background="#C4C4C4" />
	    <TableRow>
	        <View
	        	android:layout_height="80dp"
	        	android:layout_width="250dp"
	        	android:background="#292929"
	        />
	        <TextView 
	        	android:layout_height="80dp"
	        	android:text="#292929"
				android:gravity="center"/>
	    </TableRow>
		<View
			android:layout_height="2dip"
	        android:background="#C4C4C4" />
	    <TableRow>
	        <View
	        	android:layout_height="80dp"
	        	android:layout_width="250dp"
	        	android:background="#8A500E"
	        />
	        <TextView 
	        	android:layout_height="80dp"
	        	android:text="#8A500E"
				android:gravity="center"/>
	    </TableRow>
		<View
			android:layout_height="2dip"
	        android:background="#C4C4C4" />
	    <TableRow>
	        <View
	        	android:layout_height="80dp"
	        	android:layout_width="250dp"
	        	android:background="#D67C15"
	        />
	        <TextView 
	        	android:layout_height="80dp"
	        	android:text="#D67C15"
				android:gravity="center"/>
	    </TableRow>
		<View
			android:layout_height="2dip"
	        android:background="#C4C4C4" />
	    <TableRow>
	        <View
	        	
	        	android:layout_height="80dp"
	        	android:layout_width="250dp"	
	        	android:background="#8A270E"
	        />
	        <TextView 
	        	android:layout_height="80dp"
	        	android:text="#8A270E"
				android:gravity="center"/>
	    </TableRow>
		<View
			android:layout_height="2dip"
	        android:background="#C4C4C4" />
	    <TableRow>
	        <View
	        	android:layout_height="80dp"
	        	android:layout_width="250dp"
	        	android:background="#D63C16"
	        />
	        <TextView 
	        	android:layout_height="80dp"
	        	android:text="#D63C16"
				android:gravity="center"/>
	    </TableRow>
	</TableLayout>
</ScrollView>

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值