<?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:stretchColumns="1" > <TableRow> <TextView android:gravity="right" android:textStyle="bold" android:padding="3dip" android:text="用户名称:" /> <EditText android:id="@+id/username" android:padding="3dip" android:scrollHorizontally="true" /> </TableRow> <TableRow> <TextView android:gravity="right" android:textStyle="bold" android:padding="3dip" android:text="用户密码:" /> <EditText android:id="@+id/password" android:padding="3dip" android:password="true" /> </TableRow> <TableRow android:gravity="right"> <Button android:id="@+id/cancel" android:text="取消" /> <Button android:id="@+id/login" android:text="登录" /> </TableRow> </TableLayout>在上面的布局代码中一共有3行,即3个TableRow,每一个TableRow里边都有两个单元格。
package com.rainsong.layoutdemo; import android.app.Activity; import android.os.Bundle; public class TableLayoutActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.table_layout); } }
原文地址:http://blog.csdn.net/hantangsongming/article/details/40855893