亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

詳解Android TableLayout表格布局

 更新時間:2016年02月24日 09:03:15   作者:gisoracle  
表格布局的標(biāo)簽是TableLayout,TableLayout繼承了LinearLayout。所以它依然是一個線性布局,通過本文給大家介紹Android TableLayout表格布局,感興趣的朋友一起學(xué)習(xí)吧

表格布局的標(biāo)簽是TableLayout,TableLayout繼承了LinearLayout。所以它依然是一個線性布局。

前言:

1、TableLayout簡介

2、TableLayout行列數(shù)的確定

3、TableLayout可設(shè)置的屬性詳解

4、一個包含4個TableLayout布局的實例及效果圖

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="3dip"
>
<!-- 第1個TableLayout,用于描述表中的列屬性。第0列可伸展,第1列可收縮 ,第2列被隱藏-->
<TextView
android:text="數(shù)字鍵盤"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textSize="20sp"
android:background="#7f00ffff"/>
<TableLayout
android:id="@+id/table2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="1dip">
<TableRow>
<Button android:text="0"/>
<Button android:text="1"/>
<Button android:text="2"/>
<Button android:text="+"/>
<Button android:text="="/>
</TableRow>
<TableRow>
<Button android:text="3"/>
<Button android:text="4"/>
<Button android:text="5"/>
<Button android:text="-"/>
<Button android:text="*"/>
</TableRow>
<TableRow>
<Button android:text="6"/>
<Button android:text="7"/>
<Button android:text="8"/>
<Button android:text="9"/>
<Button android:text="/"/>
</TableRow>
</TableLayout>
</LinearLayout>

一、Tablelayout簡介

Tablelayout類以行和列的形式對控件進行管理,每一行為一個TableRow對象,或一個View控件。
當(dāng)為TableRow對象時,可在TableRow下添加子控件,默認(rèn)情況下,每個子控件占據(jù)一列。
當(dāng)為View時,該View將獨占一行。

二、TableLayout行列數(shù)的確定

TableLayout的行數(shù)由開發(fā)人員直接指定,即有多少個TableRow對象(或View控件),就有多少行。

TableLayout的列數(shù)等于含有最多子控件的TableRow的列數(shù)。如第一TableRow含2個子控件,第二個TableRow含3個,第三個TableRow含4個,那么該TableLayout的列數(shù)為4.

三、TableLayout可設(shè)置的屬性詳解

TableLayout可設(shè)置的屬性包括全局屬性及單元格屬性。

1、全局屬性也即列屬性,有以下3個參數(shù):

android:stretchColumns 設(shè)置可伸展的列。該列可以向行方向伸展,最多可占據(jù)一整行。

android:shrinkColumns 設(shè)置可收縮的列。當(dāng)該列子控件的內(nèi)容太多,已經(jīng)擠滿所在行,那么該子控件的內(nèi)容將往列方向顯示。

android:collapseColumns 設(shè)置要隱藏的列。

示例:

android:stretchColumns="0" 第0列可伸展

android:shrinkColumns="1,2" 第1,2列皆可收縮

android:collapseColumns="*" 隱藏所有行

說明:列可以同時具備stretchColumns及shrinkColumns屬性,若此,那么當(dāng)該列的內(nèi)容N多時,將“多行”顯示其內(nèi)容。(這里不是真正的多行,而是系統(tǒng)根據(jù)需要自動調(diào)節(jié)該行的layout_height)

2、單元格屬性,有以下2個參數(shù):

android:layout_column 指定該單元格在第幾列顯示
android:layout_span 指定該單元格占據(jù)的列數(shù)(未指定時,為1)

示例:

android:layout_column="1" 該控件顯示在第1列
android:layout_span="2" 該控件占據(jù)2列

說明:一個控件也可以同時具備這兩個特性。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="3dip"
>
<!-- 第1個TableLayout,用于描述表中的列屬性。第0列可伸展,第1列可收縮 ,第2列被隱藏-->
<TextView
android:text="表1:全局設(shè)置:列屬性設(shè)置"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textSize="15sp"
android:background="#7f00ffff"/>
<TableLayout
android:id="@+id/table1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="0"
android:shrinkColumns="1"
android:collapseColumns="2"
android:padding="3dip">
<TableRow>
<Button android:text="該列可伸展"/>
<Button android:text="該列可收縮"/>
<Button android:text="我被隱藏了"/>
</TableRow>
<TableRow>
<TextView android:text="我向行方向伸展,我可以很長 "/>
<TextView android:text="我向列方向收縮,我可以很深"/>
</TableRow>
</TableLayout>
<!-- 第2個TableLayout,用于描述表中單元格的屬性,包括:android:layout_column 及android:layout_span-->
<TextView
android:text="表2:單元格設(shè)置:指定單元格屬性設(shè)置"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textSize="15sp"
android:background="#7f00ffff"/>
<TableLayout
android:id="@+id/table2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="3dip">
<TableRow>
<Button android:text="第0列"/>
<Button android:text="第1列"/>
<Button android:text="第2列"/>
</TableRow>
<TableRow>
<TextView android:text="我被指定在第2列" android:layout_column="2"/>
</TableRow>
<TableRow>
<TextView
android:text="我跨1到2列,不信你看!"
android:layout_column="1"
android:layout_span="2"
/>
</TableRow>
</TableLayout>
<!-- 第3個TableLayout,使用可伸展特性布局-->
<TextView
android:text="表3:應(yīng)用一,非均勻布局"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textSize="15sp"
android:background="#7f00ffff"/>
<TableLayout
android:id="@+id/table3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="*"
android:padding="3dip"
>
<TableRow>
<Button android:text="一" ></Button>
<Button android:text="兩字"></Button>
<Button android:text="三個字" ></Button>
</TableRow>
</TableLayout>
<!-- 第4個TableLayout,使用可伸展特性,并指定每個控件寬度一致,如1dip-->
<TextView
android:text="表4:應(yīng)用二,均勻布局"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textSize="15sp"
android:background="#7f00ffff"/>
<TableLayout
android:id="@+id/table4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="*"
android:padding="3dip"
>
<TableRow>
<Button android:text="一" android:layout_width="1dip"></Button>
<Button android:text="兩字" android:layout_width="1dip"></Button>
<Button android:text="三個字" android:layout_width="1dip"></Button>
</TableRow>
</TableLayout>
<TextView
android:text="表5:應(yīng)用三,均勻布局"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textSize="15sp"
android:background="#7f00ffff"/>
<TableLayout
android:id="@+id/table5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="*"
android:padding="6dip"
>
<TableRow>
<Button android:text="一" android:layout_width="1dip"></Button>
<Button android:text="兩字" android:layout_width="1dip"></Button>
<Button android:text="三個字" android:layout_width="1dip"></Button>
<Button android:text="四個個字" android:layout_width="1dip"></Button>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="1dip"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button" />
</TableRow>
</TableLayout>
</LinearLayout>

以上內(nèi)容是小逼給大家介紹的Android TableLayout表格布局,希望對大家有所幫助!

相關(guān)文章

  • android開發(fā)教程之卸載sd卡對MediaServer的處理

    android開發(fā)教程之卸載sd卡對MediaServer的處理

    Android中如果MediaServer訪問SD卡上的音頻文件,卸載SD卡的時候,就會kill掉MediaServer,卸載SD卡上必要條件就是沒有進程訪問SD卡上的資源文件。Kill掉MediaServer的進程后,MediaServer會重新啟動。
    2014-02-02
  • js驗證手機號碼

    js驗證手機號碼

    本文主要分享了js驗證手機號碼的示例代碼,具有一定的參考價值,下面跟著小編一起來看下吧
    2017-01-01
  • Android跳轉(zhuǎn)系統(tǒng)設(shè)置Settings的各個界面詳解

    Android跳轉(zhuǎn)系統(tǒng)設(shè)置Settings的各個界面詳解

    系統(tǒng)設(shè)置Settings中定義的一些常用的各界面ACTION常量,下面這篇文章主要給大家介紹了關(guān)于Android跳轉(zhuǎn)系統(tǒng)設(shè)置Settings的各個界面,文中介紹非常詳細,需要的朋友可以參考下
    2023-01-01
  • Android入門之bindService的用法詳解

    Android入門之bindService的用法詳解

    indService大家可以認(rèn)為它是和Android的一個共生體。即這個service所屬的activity如果消亡那么bindService也會消亡。本文將通過簡單的例子帶大家了解一下bindService的用法,感興趣的可以了解一下
    2022-12-12
  • ubuntu用wifi連接android調(diào)試程序的步驟

    ubuntu用wifi連接android調(diào)試程序的步驟

    這篇文章主要介紹了ubuntu用wifi連接android調(diào)試程序的步驟,需要的朋友可以參考下
    2014-02-02
  • android實現(xiàn)簡單進度條ProgressBar效果

    android實現(xiàn)簡單進度條ProgressBar效果

    這篇文章主要為大家詳細介紹了android實現(xiàn)簡單進度條ProgressBar效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-07-07
  • android surfaceView實現(xiàn)播放視頻功能

    android surfaceView實現(xiàn)播放視頻功能

    這篇文章主要為大家詳細介紹了android surfaceView實現(xiàn)播放視頻功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-05-05
  • Android如何繪制發(fā)光效果詳解

    Android如何繪制發(fā)光效果詳解

    這篇文章主要給大家介紹了關(guān)于Android如何繪制發(fā)光效果的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對各位Android開發(fā)者們具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07
  • Android仿360市場下載按鈕的實現(xiàn)方法

    Android仿360市場下載按鈕的實現(xiàn)方法

    這篇文章主要給大家介紹了關(guān)于利用Android實現(xiàn)360市場下載按鈕效果的方法,文中給出了詳細的示例代碼供大家參考學(xué)習(xí),并在文末給出了源碼供大家下載,需要的朋友們下面跟著小編一起來學(xué)習(xí)學(xué)習(xí)吧。
    2017-05-05
  • 21天學(xué)習(xí)android開發(fā)教程之XML解析與生成

    21天學(xué)習(xí)android開發(fā)教程之XML解析與生成

    21天學(xué)習(xí)android開發(fā)教程之XML解析與生成,使用SAX來解析XML,在Android里面可以使用SAX和DOM,DOM需要把整個XML文件讀入內(nèi)存再解析,比較消耗內(nèi)存,而SAX基于事件驅(qū)動的處理方式,可以在各節(jié)點觸發(fā)回調(diào)函數(shù),需要的朋友可以參考下
    2016-02-02

最新評論