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


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. CreateProcess error = 2,系统找不到指定的文件
  3. Android(安卓)工程混淆后无法找到自定义控件类的解决方案
  4. android 用 XML 自定义边框(只上下边框有色)
  5. Android(安卓)自定义view 基础篇(一)
  6. Android中如何让TextView显示指定的行数并且多出的部分显示省略
  7. Android(安卓)自定义View及其在布局文件中的使用示例
  8. Android自定义视图四:定制onMeasure强制显示为方形
  9. Android(安卓)中自定义控件和属性(attr.xml,declare-styleable,T

随机推荐

  1. Android集成Huawei PUSH(四)——客户端开发
  2. android 分辨率问题
  3. Android通过JNI调用驱动程序(完全解析实
  4. Android应用程序添加自定义的property属
  5. Android(1.初识Android应用程序目录)
  6. android 出现gen already exists but is
  7. Android中定时器Timer和TimerTask的启动,
  8. 第一章 开始启程,你的第一行Android代码
  9. Android之 UI主线程ZT
  10. android中跨进程通讯的4种方式