1.LinearLayout线性布局
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
vertical排列:里边控件高度1:1:1
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Button" />
<Button
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Button" />
<Button
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
2,RelativeLayout相对布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Button" />
<Button
android:id="@+id/btn_middle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/btn_middle"
android:layout_below="@id/btn_middle"
android:text="Button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="Button" />
</RelativeLayout>
其他常用属性:直接转载了别的博主的了 http://www.cnblogs.com/sevenyuan/archive/2010/09/16/1827940.html
// 相对于给定ID控件
android:layout_above 将该控件的底部置于给定ID的控件之上;
android:layout_below 将该控件的底部置于给定ID的控件之下;
android:layout_toLeftOf 将该控件的右边缘与给定ID的控件左边缘对齐;
android:layout_toRightOf 将该控件的左边缘与给定ID的控件右边缘对齐;
android:layout_alignBaseline 将该控件的baseline与给定ID的baseline对齐;
android:layout_alignTop 将该控件的顶部边缘与给定ID的顶部边缘对齐;
android:layout_alignBottom 将该控件的底部边缘与给定ID的底部边缘对齐;
android:layout_alignLeft 将该控件的左边缘与给定ID的左边缘对齐;
android:layout_alignRight 将该控件的右边缘与给定ID的右边缘对齐;
// 相对于父组件
android:layout_alignParentTop 如果为true,将该控件的顶部与其父控件的顶部对齐;
android:layout_alignParentBottom 如果为true,将该控件的底部与其父控件的底部对齐;
android:layout_alignParentLeft 如果为true,将该控件的左部与其父控件的左部对齐;
android:layout_alignParentRight 如果为true,将该控件的右部与其父控件的右部对齐;
// 居中
android:layout_centerHorizontal 如果为true,将该控件的置于水平居中;
android:layout_centerVertical 如果为true,将该控件的置于垂直居中;
android:layout_centerInParent 如果为true,将该控件的置于父控件的中央;
// 指定移动像素
android:layout_marginTop 上偏移的值;
android:layout_marginBottom 下偏移的值;
android:layout_marginLeft 左偏移的值;
android:layout_marginRight 右偏移的值;
3,FrameLayout布局
帧布局中的每一个组件都代表一个画面,默认以屏幕左上角作为( 0,0 )坐标,按组件定义的先后顺序依次逐屏显示 , 后面出现的会覆盖前面的画面 。 用该布局可以实现动画效果 。帧布局的大小由最大的子控件决定,帧布局在动画中应用比较多。
常用属性:foreground 设置该帧布局容器的前景图像 foregroundGravity设置前景图像的显示位置
学习帧布局:转载,http://blog.youkuaiyun.com/lihongjian944043440/article/details/7055589 和 http://www.it165.net/pro/html/201403/10735.html
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#FF6143" />
<TextView
android:layout_width="150dp"
android:layout_height="150dp"
android:background="#7BFE00" />
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#FFFF00" />
</FrameLayout>
4,TableLayout布局
格布局类似Html里面的Table。每一个TableLayout里面有表格行TableRow,TableRow里面可以具体定义每一个元素,设定他的对齐方式 android:gravity="",如:
<TableLayout > 是顶级元素,说明采用的是表格布局
<TableRow> 定义一个行
<TextView > 定义一个单元格的内容
在第二个例子里的EditText代码改成这样:
<TableRow>
<EditText android:layout_span="2"/>
<EditText android:layout_column="2"/>
</TableRow>
Layout_span=”2” 伸展2倍
Layout_column=”2” 位置固定到第三列
5,AbsoluteLayout布局
<AbsoluteLayout 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"
tools:context=".MainActivity" >
<TextView
android:id="@+id/txt1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="绝对布局的使用"
android:layout_x="80px"
android:layout_y="80px"/>
<TextView
android:id="@+id/txt2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="2.3之后废除了"
android:layout_x="120px"
android:layout_y="120px"/>
<ImageView
android:id="@+id/img1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_x="80px"
android:layout_y="180px"
android:src="@drawable/ic_launcher"/>
</AbsoluteLayout>