`

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>

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics