Android ApiDemos示例解析(158):Views->Layouts->TableLayout->03.Long Content
2012-09-07 06:59
381 查看
本例介绍了TableLayout的shrinkColumns 的属性,shrinkColumns 定义可以Shrinkable 的列的序号,以逗号分开,可以使用‘*’代表所有列。
本例的第二行由四列,其中第四列显示了一个长文字内容 (Save Document ) Too Long ,无法将整个行的内容放在一行,此时指定了Shrinkable的列(2,3) 可以收缩以适应表格大小。
本例Google 提供的例子无法显示这个效果,因为在VGA模式下,too long 并不长:-) ,完全可以在一列显示完。
请将string/table_layout_3_too_long 的值改成”Too Long String”
<TableLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:shrinkColumns=”2, 3″>
<!– Rows have different number of columns and content doesn’t fit on
screen: column 4 of row 2 shrinks all of the other columns –>
<TableRow>
< TextView
android:text=”@string/table_layout_3_star”
android:padding=”3dip” />
<TextView
android:text=”@string/table_layout_3_open”
android:padding=”3dip” />
<TextView
android:text=”@string/table_layout_3_open_shortcut”
android:padding=”3dip” />
< /TableRow>
<TableRow>
< TextView
android:text=”@string/table_layout_3_triple_star”
android:padding=”3dip” />
<TextView
android:text=”@string/table_layout_3_save”
android:padding=”3dip” />
<TextView
android:text=”@string/table_layout_3_save_shortcut”
android:padding=”3dip” />
<TextView
android:text=”@string/table_layout_3_too_long”
android:padding=”3dip” />
< /TableRow>
<TableRow>
< TextView
android:text=”@string/table_layout_3_star”
android:padding=”3dip” />
<TextView
android:text=”@string/table_layout_3_quit”
android:padding=”3dip” />
<TextView
android:text=”@string/table_layout_3_quit_shortcut”
android:padding=”3dip” />
< /TableRow>
< /TableLayout>
![](http://www.imobilebbs.com/wordpress/wp-content/uploads/2011/07/20110710009.png)
可以看到设置了shrinkColumns=”2, 3″,该两列(第三和第四列缩小以适应屏幕)
本例的第二行由四列,其中第四列显示了一个长文字内容 (Save Document ) Too Long ,无法将整个行的内容放在一行,此时指定了Shrinkable的列(2,3) 可以收缩以适应表格大小。
本例Google 提供的例子无法显示这个效果,因为在VGA模式下,too long 并不长:-) ,完全可以在一列显示完。
请将string/table_layout_3_too_long 的值改成”Too Long String”
<TableLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:shrinkColumns=”2, 3″>
<!– Rows have different number of columns and content doesn’t fit on
screen: column 4 of row 2 shrinks all of the other columns –>
<TableRow>
< TextView
android:text=”@string/table_layout_3_star”
android:padding=”3dip” />
<TextView
android:text=”@string/table_layout_3_open”
android:padding=”3dip” />
<TextView
android:text=”@string/table_layout_3_open_shortcut”
android:padding=”3dip” />
< /TableRow>
<TableRow>
< TextView
android:text=”@string/table_layout_3_triple_star”
android:padding=”3dip” />
<TextView
android:text=”@string/table_layout_3_save”
android:padding=”3dip” />
<TextView
android:text=”@string/table_layout_3_save_shortcut”
android:padding=”3dip” />
<TextView
android:text=”@string/table_layout_3_too_long”
android:padding=”3dip” />
< /TableRow>
<TableRow>
< TextView
android:text=”@string/table_layout_3_star”
android:padding=”3dip” />
<TextView
android:text=”@string/table_layout_3_quit”
android:padding=”3dip” />
<TextView
android:text=”@string/table_layout_3_quit_shortcut”
android:padding=”3dip” />
< /TableRow>
< /TableLayout>
![](http://www.imobilebbs.com/wordpress/wp-content/uploads/2011/07/20110710009.png)
可以看到设置了shrinkColumns=”2, 3″,该两列(第三和第四列缩小以适应屏幕)
相关文章推荐
- Android ApiDemos示例解析(163):Views->Layouts->TableLayout->08. Toggle Stretch
- Android ApiDemos示例解析(162):Views->Layouts->TableLayout->07. Column Collapse
- Android ApiDemos示例解析(159):Views->Layouts->TableLayout->04.Stretchable
- Android ApiDemos示例解析(156):Views->Layouts->TableLayout->01. Basic
- Android ApiDemos示例解析(164):Views->Layouts->TableLayout->09. Toggle Shrink
- Android ApiDemos示例解析(165):Views->Layouts->TableLayout->10. Simple Form
- Android ApiDemos示例解析(161):Views->Layouts->TableLayout->06. More Spanning and Stretchable
- Android ApiDemos示例解析(160):Views->Layouts->TableLayout->05. Spanning and Stretchable
- Android ApiDemos示例解析(166):Views->Layouts->TableLayout->11. Gravity
- Android ApiDemos示例解析(167):Views->Layouts->TableLayout->12. Cell Spanning
- Android ApiDemos示例解析(157):Views->Layouts->TableLayout->02. Empty Cells
- Android ApiDemos示例解析(150):Views->Layouts->LinearLayout->10. Background Image
- Android ApiDemos示例解析(152):Views->Layouts->RelativeLayout->2.Simple Form
- Android ApiDemos示例解析(147):Views->Layouts->LinearLayout->7. Fill Parent
- Android ApiDemos示例解析(151):Views->Layouts->RelativeLayout->1. Vertical
- Android ApiDemos示例解析(148):Views->Layouts->LinearLayout->8. Gravity
- Android ApiDemos示例解析(154):Views->Layouts->ScrollView->2. Long
- Android ApiDemos示例解析(143):Views->Layouts->LinearLayout->3. Vertical (Padded)
- Android ApiDemos示例解析(149):Views->Layouts->LinearLayout->9. Layout Weight
- Android ApiDemos示例解析(141):Views->Layouts->LinearLayout->1. Vertical