TableLayout

来源:互联网 发布:淘宝怎样套现信用卡 编辑:程序博客网 时间:2024/06/13 00:05

继承自LinearLayout
不用明确声明行,列
通过添加TableRow来添加行
TableRow也是组件,向其中添加自组件构成列
若直接向TableLayout中添加组件,则此组件直接为一行

特有的xml属性
android:collapseColumns 要被隐藏的列的序号
android:shrinkColumns 允许被收缩的列(适应父布局)
android:stretchColumns 允许被拉伸的列(保证填满剩余空间)

tip:
推荐将字符串集中放到xml文件中管理,包括按钮上显式的文本之类的

布局文件

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="match_parent"    android:layout_height="match_parent"    >    <!--第一个表格布局,第二列允许收缩,第三列允许拉伸-->    <TableLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:shrinkColumns="1"        android:stretchColumns="3"        android:collapseColumns="2">        <Button            android:layout_height="wrap_content"            android:layout_width="wrap_content"            android:text="占一行的按钮"/>        <TableRow>            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="1普通按钮"/>            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="2收缩按钮"/>            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="3隐藏按钮"/>            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="4拉伸按钮"/>        </TableRow>``   </TableLayout></LinearLayout>

运行结果

原创粉丝点击