TableLayout,顾名思义,代表表格布局。类似HTML编程中的<table>。在某些布局时较优越。
本人不经常使用,在登录表单页面的编写时,偶尔会涉及到。
TableLayout的优越性之一就是可以在TableLayout属性下控制拉伸,而<TableRow>则表示一行。比如:
效果如图:
效果如图:
效果如图:
效果如图:
让页面显示更多view,如图示:
本人不经常使用,在登录表单页面的编写时,偶尔会涉及到。
因为用的不多,所以不熟。今天挑出来专门研究下。
在xml中,一般都是这种结构进行使用:
<TableLayout>
<TableRow>
<view />
</TableRow>
</TableLayout>
TableLayout的优越性之一就是可以在TableLayout属性下控制拉伸,而<TableRow>则表示一行。比如:
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="2"
>
<TableRow>
<Button android:hint="helloworld"/>
<Button android:hint="helloworld"/>
<Button android:hint="helloworld"/>
</TableRow>
</TableLayout>
效果如图:
也可以改成android:stretchColumns="0,2",这时候代表第一列和第三列拉伸。
在LinearLayout下有layout_weight属性来进行拉伸控制,在这里,也可以不使用stretchColumns,使用weight控制。比如:
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TableRow>
<Button android:hint="helloworld"
android:layout_weight="1"/>
<Button android:hint="helloworld"/>
<Button android:hint="helloworld"
android:layout_weight="1"/>
</TableRow>
</TableLayout>
效果如图:
和第二个例子一模一样,只是代码的书写量变多了,也体现了程序员的技术水平。
collapseColumns的属性使用:
编写如下代码:
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1,2"
android:collapseColumns="1"
>
<TableRow>
<Button android:hint="helloworld0"/>
<Button android:hint="helloworld1"/>
<Button android:hint="helloworld2"/>
<Button android:hint="helloworld3"/>
</TableRow>
</TableLayout>
效果如图:
collapseColumns表示第几列缩进。
android:shrinkColumns的使用:
编写如下代码:
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1,2"
android:collapseColumns="1"
>
<TableRow>
<Button android:hint="helloworld0222222222222222222222222222222"/>
<Button android:hint="helloworld1333333333333333333333333333333"/>
<Button android:hint="helloworld2444444444444444444444444444444"/>
<Button android:hint="helloworld3444444444444444444444444444444"/>
</TableRow>
</TableLayout>
效果如图:
可以看到有些button已经被挤出来了。
这时候使用shrinkColumns属性:
<pre name="code" class="html"><TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:shrinkColumns="0,1,2,3"
>
<TableRow>
<Button android:hint="helloworld0222222222222222222222222222222"/>
<Button android:hint="helloworld1333333333333333333333333333333"/>
<Button android:hint="helloworld2444444444444444444444444444444"/>
<Button android:hint="helloworld3444444444444444444444444444444"/>
</TableRow>
</TableLayout>
让页面显示更多view,如图示:
掌握这么多,我猜基本上TableLayout就差不多可以了吧。