LinearLayout
LinearLayout,线性布局。Android中比较常用的布局容器之一。其内部的控件按水平或垂直方向依次线性排列。线性布局区别于其他主要布局方式最重要的xml属性是,android:orientation ,用于设置线性布局中控件的排列方向。处于线性布局中的控件可以使用属性android:layout_weight设置其在空间分配上的权重。
·线性布局
- 线性布局中的子容器或控件,按先后顺序水平或垂直的排列
·主要属性:
- android:orientation
- android:layout_weight
·主要方法:
- addview(View v)
TableLayout
TableLayout,表格布局。该布局扩展自LinearLayout,被设定为一个垂直线性布局。其内部可以包含TableRow,作为表格行。TableRow同样是Linearlayout的子类,被定义为一个水平线性布局。二者搭配使用,构成表格布局。位于表格布局内的控件,可以无需设置其本身的布局宽和布局高。TableLayout最重要的xml属性包括:android:collapseColumns、android:stretchColumns、android:shrinkColumns
·表格布局
- 继承自LinearLayout
- 控件垂直线性排列,默认宽度填充整行,高度适应内容
- 常与TableRow配合使用
·主要属性
- android:collapseColumns 定义影藏某列(多个列用“,”分开)
- android:stretchColumns 定义拉伸某列
- android: shrinkColumns 定义收缩某列
·TableRow
- 继承自linearLayout
- 控件水平线性排列,默认高度,宽度适应内容
实例:
XML:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="1,2"
android:shrinkColumns="1"
android:collapseColumns="3"
>
<TextView
android:text="第一行"
android:background="#ffac9900"/>
<TableRow >
<TextView
android:text="第一列3242342"
android:background="#acf33322"/>
<TextView
android:text="2第二列3242342第二列3242342第二列3242342"
android:background="#12f33322"/>
<TextView
android:text="第三列3242342"
android:background="#abc33322"/>
<TextView
android:text="第四列3242342"
android:background="#abc33322"/>
</TableRow>