標籤:
瞭解字面上TableLayout一個表格樣式布局。這種布局將包括以行和列的形式的元件被布置。表格列的數目是列的各行中的最大數目。當然,表格裡面的單元格它能夠清空。
執行個體:LayoutDemo
執行效果:
代碼清單:
布局檔案:table_layout.xml
<?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裡邊都有兩個單元格。
TableLayout標籤定義了一個表格布局(TableLayout).
TableRow標籤定義了表格布局裡邊的一行。每一行裡邊能夠自由的加入一些組件,比方在上邊我們主要加入了button組件和編輯框組件。
Java源碼檔案:TableLayoutActivity.java
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); }}
Android UI布局TableLayout