在XML布局文件中定义表格布局管理器的基本语法:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
属性列表
>
<TableRow 属性列表> 需要添加的UI组件</TableRow>
多个TableRow
</TableLayout>


TableLayout支持的XML属性:
android:collapseColumns设置要被隐藏的序列号(从0开始,用','分离)
android:shrinkColumns设置允许被收缩的序列号(从0开始,用','分离)
android:stretchColumns设置允许被拉伸的序列号(从0开始,用','分离)


下面使用表格布局实现一个用户登录的界面

效果图:

实现代码:

MainActivity:

package com.example.test;import android.app.Activity;import android.os.Bundle;import android.view.MotionEvent;import android.view.View;import android.view.View.OnTouchListener;import android.widget.FrameLayout;public class MainActivity extends Activity {  @Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);}}

res/layout/main.xml:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:id="@+id/tableLayout1"    android:gravity="center_vertical"    android:background="#000000"    android:stretchColumns="0,3"    > <!-- 第一行 --> <TableRow android:id="@+id/tableRow1"     android:layout_width="wrap_content"     android:layout_height="wrap_content">     <TextView/>     <TextView android:text="用户名"         android:id="@+id/textView1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:textSize="24px"         android:textColor="#FFFFFF"/>     <EditText android:id="@+id/editView1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:background="#FFFFFF"         android:minWidth="200px"/>     <TextView/> </TableRow> <!-- 第二行 --> <TableRow android:id="@+id/tableRow2"     android:layout_marginTop="10px"     android:layout_width="wrap_content"     android:layout_height="wrap_content">     <TextView/>     <TextView android:text="密    码:"         android:id="@+id/textView2"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:textSize="24px"         android:textColor="#FFFFFF"/>     <EditText android:id="@+id/editView1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:background="#FFFFFF"         android:textSize="24px"         android:inputType="textPassword"/>     <TextView/> </TableRow> <!-- 第三行 --> <TableRow android:id="@+id/tableRow3"     android:layout_width="wrap_content"     android:layout_height="wrap_content">     <TextView/>     <Button android:text="登录"         android:id="@+id/button1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"/>     <Button android:text="退出"         android:id="@+id/button2"         android:layout_width="wrap_content"         android:layout_height="wrap_content"/>     <TextView/> </TableRow></TableLayout>

转载请注明出处:http://blog.csdn.net/acmman/article/details/44728787

更多相关文章

  1. Android属性汇总
  2. FrameLayout 帧布局
  3. android:layout_weight的真实含义
  4. android:configChanges属性
  5. Android(安卓)TextView属性详解
  6. android自定义属性
  7. GestureOverlayView属性
  8. android:layout_weight
  9. android组建属性及使用许可

随机推荐

  1. sqlserver isnull在数据库查询中的应用
  2. SQL 比较一个集合是否在另一个集合里存在
  3. 动态给表添加删除字段并同时修改它的插入
  4. SQL对时间处理的语句小结
  5. sqlserver 数据库学习笔记
  6. SQL中exists的使用方法
  7. SQLServer中的切割字符串SplitString函数
  8. 用SQL语句添加删除修改字段、一些表与字
  9. mssql存储过程表名和字段名为变量的实现
  10. 通过T-SQL语句实现数据库备份与还原的代