Android学习笔记——布局
2015-04-12 15:06
169 查看
一、线性布局
<xml version="1.0" encoding="utf-8">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom|center_horizontal"
>
**********Your Code******
</LinearLayout>
LinearLayout 的常用XML属性:
android:gravity -->setGravity(int) 对齐方式值有:top、bottom、left、right、center_vertical、fill_vertical、center_horizontal、fill_horizontal、center、fill、clip_vertical、clip_horizontal
android:orientation -->setOrientaiton(int) 排列方式:horizontal、vertical
二、表格布局
<TableLayout android:id="@+id/TableLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:collapseColumns= "1"<!--影藏行-->
android:shrinkColumns="2"[b]<!--压缩行-->[/b]
android:stetchColumns="3"[b]<!--拉升行-->[/b]
>
<!--------独自占一行-------->
<Button android:id="@+/idOK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮"
/>
<!-----------添加表格行------------->
<TableRow>
<Button android:id="@+/idOK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮"
/>
</TableRow>
</TableLayout>
三、帧布局FrameLayout
帧布局容器为每个加入其中的组件创建一个空白的区域,称之为一帧;类似awt编程的CardLayout,与CardLayout的区别在于CardLayout可以将下面的Card移上来但帧布局则没提供相应的方法
android:foreground-->setForeground(Drawable)
android:foregroundGravity-->setForegroundGravity(int) 定义绘制前景图像的gravity属性
四、相对布局
RelativeLayout内子组建的位置总是相对兄弟组件,父容器来决定,因此称之为相对布局。
A组件位置由B定义,则需先顶一下B,再定义A
RelativeLayout的xml属性、方法
android:gravity-->setGravity(int) 设置该布局容器子组件的对其防水
android:ignoreGravity--->setIgnoreGravity(int) 设置哪个组件不受gravity组件影响
RelativeLayout.LayoutParams的Boolean属性
android:layout_centerHorizontal 设置是否水平居中
android:layout_centerVertical 设置是否垂直居中
android:layout_centerInParent 设置是否为布局中央显示
android:layout_alignParentBottom 设置是否容器底端对其
android:layout_alignParentLeft 设置是否容器左端对其
android:layout_alignParentRight:设置是否容器右端对其
android:layout_alignParentTop 设置是否容器顶端对其
RelativeLayout.LayoutParams的ID属性
android:layout_toRightOf 设置位于给定组件的右端对其
android:layout_toLeftOf
android:layout_above
android:layout_bellow
android:layout_alignTop 设置与给定组件的上边界对其
android:layout_alignLeft
android:layout_alignRight
android:layout_alignBottom
五、绝对布局
通过X坐标、Y坐标来定义
layout_x,layout_y
<xml version="1.0" encoding="utf-8">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom|center_horizontal"
>
**********Your Code******
</LinearLayout>
LinearLayout 的常用XML属性:
android:gravity -->setGravity(int) 对齐方式值有:top、bottom、left、right、center_vertical、fill_vertical、center_horizontal、fill_horizontal、center、fill、clip_vertical、clip_horizontal
android:orientation -->setOrientaiton(int) 排列方式:horizontal、vertical
二、表格布局
<TableLayout android:id="@+id/TableLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:collapseColumns= "1"<!--影藏行-->
android:shrinkColumns="2"[b]<!--压缩行-->[/b]
android:stetchColumns="3"[b]<!--拉升行-->[/b]
>
<!--------独自占一行-------->
<Button android:id="@+/idOK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮"
/>
<!-----------添加表格行------------->
<TableRow>
<Button android:id="@+/idOK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮"
/>
</TableRow>
</TableLayout>
三、帧布局FrameLayout
帧布局容器为每个加入其中的组件创建一个空白的区域,称之为一帧;类似awt编程的CardLayout,与CardLayout的区别在于CardLayout可以将下面的Card移上来但帧布局则没提供相应的方法
android:foreground-->setForeground(Drawable)
android:foregroundGravity-->setForegroundGravity(int) 定义绘制前景图像的gravity属性
四、相对布局
RelativeLayout内子组建的位置总是相对兄弟组件,父容器来决定,因此称之为相对布局。
A组件位置由B定义,则需先顶一下B,再定义A
RelativeLayout的xml属性、方法
android:gravity-->setGravity(int) 设置该布局容器子组件的对其防水
android:ignoreGravity--->setIgnoreGravity(int) 设置哪个组件不受gravity组件影响
RelativeLayout.LayoutParams的Boolean属性
android:layout_centerHorizontal 设置是否水平居中
android:layout_centerVertical 设置是否垂直居中
android:layout_centerInParent 设置是否为布局中央显示
android:layout_alignParentBottom 设置是否容器底端对其
android:layout_alignParentLeft 设置是否容器左端对其
android:layout_alignParentRight:设置是否容器右端对其
android:layout_alignParentTop 设置是否容器顶端对其
RelativeLayout.LayoutParams的ID属性
android:layout_toRightOf 设置位于给定组件的右端对其
android:layout_toLeftOf
android:layout_above
android:layout_bellow
android:layout_alignTop 设置与给定组件的上边界对其
android:layout_alignLeft
android:layout_alignRight
android:layout_alignBottom
五、绝对布局
通过X坐标、Y坐标来定义
layout_x,layout_y
相关文章推荐
- [Android学习笔记]LinearLayout布局,剩余空间的使用
- Android学习笔记12:框架布局管理器FrameLayout
- android学习笔记(二)布局
- Android学习笔记13:表格布局管理器TableLayout
- Android学习笔记之RelativeLayout(相对布局)
- android学习笔记(13)android幀布局
- android学习笔记8 - xml布局简记
- Android学习笔记-- Activity的布局
- Android学习笔记16:布局管理器的嵌套
- Android学习笔记二十五之ListView多布局实现
- Android学习笔记-Activity的布局
- Android学习笔记_31_通过后台代码生成View对象以及动态加载XML布局文件到LinearLayout
- Android学习笔记(九) 视图的应用布局效果
- Android学习笔记001-Android五大布局-2016.7.17
- android学习笔记(7)AbsoluteLayout+FrameLayout+RelativeLayout+TableLayout四大布局方式
- Android学习笔记之布局(1)
- 兄弟连云Android学习笔记——layout(布局)
- Android学习笔记6——基本布局
- 【Android学习笔记4】用户界面(一):布局设计
- 【android学习笔记】关于相对布局RelativeLayout的各种属性介绍