1.LinerLayout 线性布局
android:gravity=""代表空间内文字基本位置,比如水平居中
android:weight=""代表权重,可以用数字表示,占总数的几分之几
android:singleLine=“”代表显示为1行,若字数很多,设置为true时,会用...表示剩余的字,设置为false时,会将所有的字显示出来
例如:
<?xml version="1.0" encoding ="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > ->垂直布局
<TextView
android:id="@+id/first"
android:text="@string/ok"
android:gravity="center_vertical"
android:textSize="35pt"
android:background="#aa0000"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dip"
android:paddingTop="20dip"
android:layout_weight="1"
android:singleLine="true"
/>
</LinearLayout>
2.TableLayout 表格布局
android:stretchColumns="2" 将某一列进行拉伸,从0开始计数
例子:
<?xml version ="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="2" ->拉伸第三列
>
<TableRow>
<TextView
android:id="@+id/a"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="3dip"
/>
<TextView
android:id="@+id/b"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="3dip"
/>
<TextView
android:id="@+id/c"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="3dip"
/>
</TableRow>
<TableRow>
<TextView
android:id="@+id/d"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="3dip"
/>
<TextView
android:id="@+id/e"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="3dip"
/>
</TableRow>
</TableLayout>
3.RelativeLayout 相对布局
padding 内边距
margin 外边距
比如marginleft=“10px” 左边外边距为10px,左边的空间要与它有10px的距离
android:layout_above="" 将该控件置于指定id控件之上
android:layout_below="" 将该控件置于指定id控件之下
android:layout_toLeftOf="" 该控件右边与指定id控件左边对齐
android:layout_toRightOf="" 该控件左边与指定id控件右边对齐
android:layout_alignBaseline="" 该控件baseline和给定id控件baseline对齐
android:layout_alignBottom="" 该控件底部和指定id控件底部对齐
android:layout_alignLeft="" 该控件左边和指定id控件左边对齐
android:layout_alignRight=""该控件右边和指定id控件右边对齐
android:layout_alignTop="" 该控件顶部和指定id控件顶部对齐
android:layout_alignParentLeft="" 如果为true,控件左边和父控件左边对齐
android:layout_alignParentRight="" 如果为true,控件右边和父控件右边对齐
android:layout_alignParentTop="" 如果为true,控件顶部和父控件顶部对齐
android:layout_alignBottom="" 如果为true,控件底部和父控件底部对齐
android:layout_centerHorizontal="" 如果为true,控件置于水平中央
android:layout_centerVertical="" 如果为true,控件置于垂直中央
android:layout_centerInParent="" 如果为true,置于父控件水平和垂直中央