在Xamarin要实现一个能整齐摆放控件的layout,这时只有用TableLayout才实现。就象在网页中,用Table对齐控件是最方便的一样。
有几个相关属性,至关重要。比如我要设计一个表格,有三列,其中中间那列是放主要内容的,宽度要宽,另外二列宽度要短,那就要这样设计:
1. <TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
这个属性设计第2列(中间列)为可伸展。
2.第1列和最后1列,设置一个较小的宽度:
<TableRow>
<TextView
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="第1列"
android:paddingLeft="10dip"
android:layout_column="0" />
第3列放了一个线性部局,里面放了一个checkbox和一个按钮
<LinearLayout
android:layout_column="2"
android:layout_width="78dip">
<CheckBox
android:layout_width="1dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/chkCHECK_CLEAR"
android:textAlignment="center"
android:gravity="center_horizontal"
android:layout_margin="0dip" />
<Button
android:id="@+id/btnClear"
android:layout_width="1dip"
android:layout_height="35dip"
android:layout_weight="2"
android:gravity="center"
android:textColor="#F00"
android:textSize="10sp"
android:text="删除"
android:layout_gravity="fill_vertical" />
</LinearLayout>
剩余的留给中间列(第2列)
这和网页中设计了固定宽度列,剩余的会自动分配给其它列类似。区别是Table_layout只有TableRow(等于TR),而没有显示地指定列(TD)。