Android学习笔记——布局

一、线性布局

<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"<!--压缩行-->

android:stetchColumns="3"<!--拉升行-->

>

<!--------独自占一行-------->

<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




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值