<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
线性布局,默认是水平对齐horizontal,vertical是垂直对齐可以嵌套使用LinearLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <LinearLayout android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <EditText android:id="@+id/editText1" android:layout_width="fill_parent" android:layout_height="wrap_content" > </EditText> </LinearLayout> <LinearLayout android:id="@+id/linearLayout2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="right" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/submit" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/cancle" /> </LinearLayout> </LinearLayout>
absoluteLayout 绝对布局
制定子控件的xy精确坐标
绝对布局,缺乏灵活性,官方不推荐使用
FrameLayout 框架布局,是以叠层的形式布局
用layout_gravity=“left|top” 这个属性控制子控件显示的位子
RelativeLayout 相对布局
android:layout_alignBaseline 该控件基线对齐给定ID的基线
android:layout_alignBottom 该控件于给定ID的控件底部对齐
android:layout_alignLeft 该控件于给定ID的控件左对齐
android:layout_alignRight 该控件于给定ID的控件右对齐
android:layout_alignTop 该控件于给定ID的控件顶对齐
android:layout_above 将该控件置于给定ID的控件之上
android:layout_below 将该控件的置于给定ID控件之下
android:layout_toLeftOf 将该控件置于给定ID的控件之左
android:layout_toRightOf 将该控件置于给定ID的控件之右
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/txt01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="111" android:background="#ff0000" /> <TextView android:id="@+id/txt02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="222" android:background="#00ff00" android:layout_below="@+id/txt01" /> </RelativeLayout>
android:layout_below="@+id/txt01" 意思是当前textview在id=txt01的textview空间之下
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dp" > <TextView android:id="@+id/txt01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="22222" android:background="#ff0000" /> <EditText android:id="@+id/edit01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/txt01" android:layout_marginTop="10dp" /> <Button android:id="@+id/btn01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="确认" android:layout_below="@id/edit01" android:layout_alignParentRight="true" /> <Button android:id="@+id/btn02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toLeftOf="@id/btn01" android:layout_below="@id/edit01" android:text="取消" /> </RelativeLayout>
android:layout_toLeftOf="@id/btn01" //在button1的左边
另外有一个android:layout_aliginBaseLine="@id+/btn"用法 是textview以button 的文字对齐
<TextView
android:id="@+id/txt01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_aliginBaseLine="@id+/btn
/>
<Button
android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="取消" />
TableLayout常用的属性:
下面放在tablelayout中
android:collapseColumns:隐藏指定的列(数组)
android:shrinkColumns:收缩指定的列以适合屏幕,不会挤出屏幕(数组)
android:stretchColumns:尽量把指定的列填充空白部分
下面方在tableRow
android:layout_column:控件放在指定的列
android:layout_span:该控件所跨越的列数
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:collapseColumns="0,1" android:shrinkColumns="2" android:stretchColumns="1" > <TableRow> <Button android:text="Button11" /> <Button android:text="Button12" /> <Button android:text="Button13" /> </TableRow> <TableRow> <Button android:text="Button21" /> <Button android:layout_span="2" android:text="Button23"
/> </TableRow> </TableLayout>
可以嵌套使用