详解Android TableLayout表格布局

2019-12-10 19:00:56刘景俊
表格布局的标签是TableLayout,TableLayout继承了LinearLayout。所以它依然是一个线性布局,通过本文给大家介绍Android TableLayout表格布局,感兴趣的朋友一起学习吧  

表格布局的标签是TableLayout,TableLayout继承了LinearLayout。所以它依然是一个线性布局。

前言:

1、TableLayout简介

2、TableLayout行列数的确定

3、TableLayout可设置的属性详解

4、一个包含4个TableLayout布局的实例及效果图

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://www.easck.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="数字键盘"
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控件。