国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android布局之TableLayout表格布局

2020-04-11 11:05:12
字體:
供稿:網(wǎng)友

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

三個(gè)常用的屬性

android:collapseColumns:設(shè)置需要被隱藏的列的序號(hào)

android:shrinkColumns:設(shè)置允許被收縮的列的列序號(hào)

android:stretchColumns:設(shè)置運(yùn)行被拉伸的列的列序號(hào)

學(xué)習(xí)導(dǎo)圖

(1)TableLayout的相關(guān)簡(jiǎn)介

  java的swing編程和html中經(jīng)常會(huì)使用到表格,可見表格的應(yīng)用開發(fā)中使用還是比較多的,同樣android也為我們提供這樣的布局方式。

(2)如何確定行數(shù)

  a:直接向TableLayout組件,直接占一行

  b:如果想在一行添加多個(gè)組件, 就需要使用TableRow中添加

  c:TableRow中有多少個(gè)組件,這一行就會(huì)有多少列

(3)三個(gè)常用屬性(都是從零開始計(jì)數(shù))

  Shrinkable:如果某一列被設(shè)置為Shrinkable,那么該列的所有單元格的寬度可以被收縮,以保證表格能適應(yīng)父容器的寬度;

  Stretchable:如果某一列被設(shè)置為Stretchable,那么該列的所有單元格的寬度可以拉伸,以保證組件完全填充表格空余空間;

  Collapsed:如果某一列被設(shè)置為Collapsed,那么該列的所有單元格的都會(huì)被隱藏;

(4)使用實(shí)例(為了演示效果沒有,所有組件都沒有設(shè)置id)

<?xml version="1.0" encoding="utf-8"?><LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical">  <!--定義第一個(gè)表格布局,指定第二列允許收縮,第三列拉伸-->  <TableLayout    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:shrinkColumns="1"    android:stretchColumns="2">    <!-- 直接添加組件會(huì)獨(dú)占一行-->    <Button      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:text="獨(dú)自占一行"      />    <TableRow>      <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="普通按鈕"/>      <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="收縮按鈕"/>      <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="拉伸按鈕"/>    </TableRow>  </TableLayout>  <!--定義第二個(gè)表格布局指定第二列隱藏-->  <TableLayout    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:collapseColumns="1">    <!-- 直接添加組件會(huì)獨(dú)占一行-->    <Button      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:text="獨(dú)自占一行"      />    <TableRow>      <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="普通按鈕"/>      <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="普通按鈕"/>      <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="普通按鈕"/>    </TableRow>  </TableLayout>  <!--定義第三個(gè)表格布局,指定第二列,第三列都可以被拉伸-->  <TableLayout    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:stretchColumns="1,2">    <!-- 直接添加組件會(huì)獨(dú)占一行-->    <Button      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:text="獨(dú)自占一行"      />    <TableRow>      <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="普通按鈕"/>      <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="拉伸按鈕"/>      <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="拉伸按鈕"/>    </TableRow>  </TableLayout></LinearLayout>

以上內(nèi)容是小編給大家介紹的android布局之TableLayout表格布局,希望大家喜歡。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 恩施市| 凉城县| 宜君县| 清涧县| 错那县| 紫阳县| 绥宁县| 榆社县| 措勤县| 开封市| 织金县| 青田县| 壤塘县| 林口县| 沾化县| 蒲城县| 广宗县| 连城县| 额尔古纳市| 确山县| 定日县| 兖州市| 从化市| 天等县| 虎林市| 噶尔县| 拜泉县| 江华| 肇庆市| 富锦市| 兴海县| 沂源县| 临清市| 尉犁县| 木兰县| 潞城市| 山丹县| 新田县| 沁水县| 堆龙德庆县| 遂溪县|