1.LinearLayout
线性布局:LinearLayout 通过android:orientation设置线性布局的方向(水平、垂直) <LinearLayout android:layout_width="fill_parent" android:layout_height="warp_content" android:orientation="vertical" //垂直 //horizontal 水平 > <EditText android:layout_width="fill_parent" android:layout_height="warp_content" /> </LinearLayout> android:gravity 用于控制布局中控件的布局位置 多个属性 如: 底部居中 则为:botton|center android:layout_weight:用于控制控件在布局中的相对大小 非负整数值
2.AbsluteLayout
指定子控件的xy精确坐标的布局(因为绝对的定位,缺乏灵活性) android:layout_x="10px" android:layout_y="10px"
3.FrameLayout:框架布局
所有添加到这个布局中的视图都以层叠的方式显示。 第一个添加的组件放到最底层,最后添加到框架中的视图显示在最上面。 上一层会覆盖下一层的控件。 android:layout_gravity="" //控件在容器中的位置
4.RelativeLayout
在这个容器内部的子元素们可以使用彼此之间的相对位置或者和容器间的相对位置进行定位。 android:layout_above 将该控件置于给定ID的控件之上 android:layout_below 将该控件的置于给定ID控件之下 android:layout_toLeftOf 将该控件置于给定ID的控件之左 android:layout_toRightOf 将该控件置于给定ID的控件之右 //控件和控件的对齐 android:layout_alignBaseline 该控件基线对齐给定ID的基线 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_alignParentBottom 如果为True,该控件位于父控件的底部 android:layout_centerHorizontal 如果为True,该控件将被置于水平方向的中央 android:layout_centerInParent 如为Ture,该控件将被置于父控件水平方向和垂直方向 android:layout_centerVertical 如果为True,该控件将被置于垂直方向的中央 使用例子: <TextView android:id="@+id/text01" android:layout_width="warp_content" android:layout_height="warp_content" /> <TextView android:id="@+id/text02" android:layout_width="warp_content" android:layout_height="warp_content" android:layout_below="@id/text01" //在id为text01的控件之下 />
5.TableLayout
TableLayout:表格布局 通过行和列定位子元素 <TableLayout ... android:collapseColumns:隐藏指定的列 android:shrinkColumns:收缩指定的列以适合屏幕,不会挤出屏幕 android:stretchColumns:尽量把指定的列填充空白部分 .... > <TableRow> <Button .... 第一行第一列 android:layout_column:控件放在指定的列 android:layout_span:该控件所跨越的列数 /> <Button .... 第一行第二列 /> ..... </TableRow> <TableRow> .... 第二行 </TableRow> </TableLayout>