Android UI布局之TableLayout

來源:互聯網
上載者:User

標籤:south   mod   edit   data   編輯   pop   public   com   pack   

從字面上瞭解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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.