您的位置:首页 > 移动开发 > Android开发

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: