TableLayout 佈局介紹

来源:互联网 发布:节流装置计算软件 编辑:程序博客网 时间:2024/06/06 09:39

TableLayout 允許我們使用表格的方式來排列控件,
以下為一個簡單的登錄界面,
通過TableRow 定義行,每加入一個TableRow即新增一行,在TableRow中每新增一個控件,即新增一列。
通過android:stretchColumns 設定第N+1行進行拉伸,以達到自動適應屏幕的作用。
通過android:inputType 指定密碼文本框為password。
通過android:layout_span 指定login按鈕佔據兩列。

<?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:layout_height="wrap_content"            android:text="Accout:"/>        <EditText             android:id="@+id/accout"            android:layout_height="wrap_content"            android:hint="input your accout"/>    </TableRow>    <TableRow >        <TextView             android:layout_height="wrap_content"            android:text="Password"/>        <EditText             android:id="@+id/password"            android:layout_height="wrap_content"            android:inputType="textPassword"/>    </TableRow>    <TableRow >        <Button             android:layout_height="wrap_content"            android:id="@+id/login"            android:layout_span = '2'            android:text="Login"/>    </TableRow>    <TableRow >        <Button             android:layout_height="wrap_content"            android:id="@+id/exit"            android:layout_span = '2'            android:text="exit"/>    </TableRow></TableLayout>
0 0