您的位置:首页 > 其它

TableLayout 佈局介紹

2016-05-23 19:13 323 查看
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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: