表格布局最基本的三个属性:


XML代码实例:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical" >    <!-- 定义第一个表格布局,指定第2列同意收缩,第3列同意拉伸 -->    <TableLayout android:id="@+id/TableLayout01"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:shrinkColumns="1"        android:stretchColumns="2"        >        <!-- 直接加入button,它自己会占一行 -->        <Button android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:id="@+id/ok1"            android:text="独"            />        <!-- 加入一个表格行 -->        <TableRow android:layout_width="match_parent" android:layout_height="wrap_content">            <Button android:id="@+id/ok2" android:layout_width="wrap_content"                android:layout_height="wrap_content" android:text="普"/>            <Button android:id="@+id/ok3" android:layout_width="wrap_content"                android:layout_height="wrap_content" android:text="收"/>            <Button android:id="@+id/ok4" android:layout_width="wrap_content"                 android:layout_height="wrap_content" android:text="拉"/>        </TableRow>    </TableLayout>        <!-- 定义第二个表格布局,指定第2列隐藏 -->    <TableLayout android:id="@+id/TableLayout02" android:layout_marginTop="30dp"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:collapseColumns="1"        >        <!-- 直接加入button,它自己会占一行 -->        <Button android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="独"            />           <TableRow android:layout_width="match_parent" android:layout_height="wrap_content">            <Button  android:layout_width="wrap_content"                android:layout_height="wrap_content" android:text="普"/>            <Button  android:layout_width="wrap_content"                android:layout_height="wrap_content" android:text="收"/>            <Button  android:layout_width="wrap_content"                 android:layout_height="wrap_content" android:text="拉"/>        </TableRow>    </TableLayout>        <!-- 定义第三个表格布局,指定第2列和第三列同意被拉伸 --><TableLayout android:id="@+id/TableLayout03"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:stretchColumns="1,2" android:layout_marginTop="30dp"    >      <Button android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="独"     />      <TableRow android:layout_width="match_parent" android:layout_height="wrap_content">            <Button  android:layout_width="wrap_content"                android:layout_height="wrap_content" android:text="普通button"/>            <Button  android:layout_width="wrap_content"                android:layout_height="wrap_content" android:text="拉"/>            <Button  android:layout_width="wrap_content"                 android:layout_height="wrap_content" android:text="拉"/>       </TableRow>       <!-- 定义一个表格行 -->      <TableRow android:layout_width="match_parent" android:layout_height="wrap_content">           <Button  android:layout_width="wrap_content"                android:layout_height="wrap_content" android:text="普"/>            <Button  android:layout_width="wrap_content"                android:layout_height="wrap_content" android:text="拉"/>      </TableRow></TableLayout></LinearLayout>

效果:


总结:

假设没实用tableRow,直接用组件,将自己独占一行,而且填充父窗体

而假设用tableRow,上下两行各列将对齐。

更多相关文章

  1. Android 学习笔记6 —— Activity 布局学习1
  2. Android 工程混淆后无法找到自定义控件类的解决方案
  3. Android布局背景颜色设置
  4. android:layout_gravity 居中布局
  5. 转:善用Android预定义样式来为我们的布局设置效果,大大节约代码量
  6. Android 五大布局
  7. Android自定义ProgressBar样式:渐变圆角水平进度条

随机推荐

  1. IBM谷歌等工程师撰写Android开发教程合集
  2. 打造android ORM框架opendroid(一)——OR
  3. Android API Guides---Web Apps
  4. Android Tool——Hierachy Viewer可视化
  5. 阅读《Android(安卓)从入门到精通》(9)——
  6. Android之数据存储-刘志远-专题视频课程
  7. 加快android的编译速度
  8. Android开发中Message, MessageQueue, lo
  9. 狂刷Android范例之3:读写外部存储设备
  10. 福利!!!你想要的Android、Java、Python、QT