TableLayout 是一种类似表格的布局,这种布局会把包含的元素以行和列进行排列。表格的列数为所有行中的最大列数;每一行可以是一个TableRow布局对象,也可以是普通的View对象,TableRow里面没一个元素占一列;TableLayout总列数由列数最多的那一行决定。
<?xml version="1.0" encoding="utf-8"?>

<TableLayout android:id="@+id/tableLayout1" xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:stretchColumns="1"

android:shrinkColumns ="1"> <!-- android:stretchColumns 第二列自动伸展-->

<TextView android:text="Please fill the form"

android:layout_span="2"

android:gravity="center"/><!--元素内容居中对齐-->

<TableRow>

<TextView android:text="用户名:"

android:gravity="right"/>

<EditText android:id="@+id/username" />

</TableRow>

<TableRow >

<TextView android:text="登录密码"/>

<EditText android:id= "@+id/password" android:password="true"/>

</TableRow>

<TableRow >

<TextView android:layout_height="2dip"

android:background="#FF909090"

android:layout_column = "1"/><!-- 指定显示的列数,这儿是第二列 -->

</TableRow>

<TableRow >

<Button android:id="@+id/cancel" android:text="取消"/>

<Button android:id="@+id/ok" android:text="登录"

android:padding="4dip"/><!-- 元素内容与边界之间保留3dip的距离 -->

</TableRow>

</TableLayout>

效果如下:





其中 android:stretchColumns=”1″ 作用是让第二列可以扩展到所有可用空间;下面我们讲一下TableLayout几个重要的属性:

collapseColumns – 设置隐藏那些列,列ID从0开始,多个列的话用”,”分隔
stretchColumns – 设置自动伸展那些列,列ID从0开始,多个列的话用”,”分隔
shrinkColumns -设置自动收缩那些列,列ID从0开始,多个列的话用”,”分隔

可以用”*”来表示所有列,同一列可以同时设置为shrinkable和stretchable。



TableRow本身也是一个Layout,里面的元素会安装水平方向依次排列,如果TableRow的父元素不是TableLayout的话,那么他会表现的像一个LinearLayout。

填写调查赚钱

更多相关文章

  1. 11、从头学Android之Android布局管理:LinerLayout线性布局
  2. Android(安卓)从源码分析View层次之ActionMode
  3. android RelativeLayout 动态添加子View
  4. Android(安卓)RecyclerView之添加Item分割线
  5. 使用LinearLayout线性布局编写左上右上左下右下中央
  6. Android(安卓)对Layout_weight属性完全解析以及使用ListView来实
  7. Appium 在 Android(安卓)UI 测试中的应用
  8. Android_UI_实现TabHost的两种方法
  9. adapter用法

随机推荐

  1. android : px dip
  2. USER 版本与ENG 版本差异
  3. Android(安卓)广播机制---BroadCast
  4. android从服务器下载文件(php+apache+win
  5. Android使用ViewPager+Fragment实现定制T
  6. xml-----属性收集
  7. activity标签总结2
  8. 【解决方法】ADT在线安装
  9. Android之WebView 防止调用系统浏览器打
  10. android样式跟主题