標籤:
1、LinearLayout
預設orientation是horizontal
注意 android:orientation="horizontal" 和 android:layout_gravity="" 在match_parent 或者 wrap_content 下的關係
layout_gravity操作的是組件的布局 gravity="right" 操作的是組件的內容
2、RelativeLayout
子控制項彼此獨立,預設是左上對齊
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_centerInParent="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@id/center"
android:layout_below="@id/center"
3、FrameLayout
因為沒有方向,所以android:layout_gravity="bottom" 上下左右均可生效
註:在tabhost中必須使用FrameLayout
4、TableLayout
TableLayout中android:stretchColumns="1":指定哪列展開填充剩餘空間
TableLayout中列預設是對齊的
TableRow 表示一行,有幾個子節點則代表有幾列
TableLayout 的直系子節點預設layout_width="match_parent" 和 layout_height="wrap_content"且無法修改
TableRow 的直系子節點預設layout_height="wrap_content" 和 layout_width="wrap_content" 且無法修改
layout_column="1" 將當前組件設定為第幾列
layout_span="2" 當前列佔兩列空間
5、AbsoluteLayout 絕對布局
layout_x 和 layout_y 指定空間所在的位置
在針對一種平台或者一種裝置即不需要做螢幕適配時可能會用到
demo:
<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" tools:context=".MainActivity" > <TableRow> <TextView android:layout_column="1" android:text="Open" /> <TextView android:gravity="right" android:text="Ctrl-C" /> </TableRow> <TableRow> <TextView android:layout_column="1" android:text="Save" /> <TextView android:gravity="right" android:text="Ctrl." /> </TableRow> <TableRow> <TextView android:layout_column="1" android:text="Save AS.." /> <TextView android:gravity="right" android:text="Ctrl-shift" /> </TableRow> <TextView android:layout_height="1dp" android:background="#000000" /> <TableRow> <TextView android:text="X" /> <TextView android:layout_span="2" android:text="import" /> </TableRow> <TableRow> <TextView android:text="X" /> <TextView android:text="Export" /> <TextView android:gravity="right" android:text="Ctrl" /> </TableRow> <TextView android:layout_height="1dp" android:background="#000000" /> <TableRow> <TextView android:layout_column="1" android:text="Qut" /> </TableRow></TableLayout>
效果:
Android中5種布局