Android UI布局之TableLayout,androidtablelayout

來源:互聯網
上載者:User

Android UI布局之TableLayout,androidtablelayout
從字面上瞭解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標籤定義了表格布局裡邊的一行。每一行裡邊可以自由的加入一些組件,比如在上邊我們主要添加了按鈕組件和編輯框組件。

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 tablelayout布局填不滿螢幕怎辦???

樓主的tablelayout的高是怎麼設定的,是否用android:layout_height="fill_parent" ;
再者tablelayout是否嵌入在LinearLayout之中,如果的是話,LinearLayout的高是否也是android:layout_height="fill_parent" 。
只要tablelayout的高設定成填充滿父控制項,其父控制項也同樣如此設定tablelayout肯定能樸滿全屏目的。
那你的幾個TableRow的中有沒有用android:layout_weight="1",加入比重。
 
android 中的tableLayout布局

<TableRow>
<Button android:id="@+id/btndel" android:layout_width="100dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="刪除" />
<Button android:id="@+id/btnupdate" android:layout_width="50dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="更新" />
<Button android:id="@+id/btnupdate" android:layout_width="70dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="更新" /> </TableRow>
你是說這種情況麼


 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.