android的六大布局

1.FrameLayout(帧布局)

FrameLayout是五大布局中最简单的一个布局,在这个布局中,整个界面被当成一块空白备用区域,所有的子元素都不能被指定放置的位置,它们统统放于这块区域的左上角,并且后面的子元素直接覆盖在前面的子元素之上,将前面的子元素部分和全部遮挡。

2.AbsoluteLayout(绝对布局)

AbsoluteLayout是绝对布局管理器,指的是指定组件的左上角绝对坐标来指定组件的布局

<?xml version="1.0" encoding="utf-8"?>

<AbsoluteLayout

    xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="vertical" android:layout_width="fill_parent"

    android:layout_height="fill_parent">

 

    <Button android:layout_width="wrap_content"

        android:layout_height="wrap_content" android:text="按钮1"

        android:layout_x="0px" android:layout_y="0px" />

    <Button android:layout_width="wrap_content"

        android:layout_height="wrap_content" android:text="按钮2"

        android:layout_x="20px" android:layout_y="20px" />

    <Button android:layout_width="wrap_content"

        android:layout_height="wrap_content" android:text="按钮3"

        android:layout_x="40px" android:layout_y="40px" />

    <Button android:layout_width="wrap_content"

        android:layout_height="wrap_content" android:text="按钮4"

        android:layout_x="60px" android:layout_y="60px" />

</AbsoluteLayout>





3.GridLayout网格布局

首先它与LinearLayout布局一样,也分为水平和垂直两种方式,默认是水平布局,一个控件挨着一个控件从左到右依次排列,但是通过指定Android:columnCount设置列数的属性后,控件会自动换行进行排列。另一方面,对于GridLayout布局中的子控件,默认按照wrap_content的方式设置其显示,这只需要在GridLayout布局中显式声明即可。

       其次,若要指定某控件显示在固定的行或列,只需设置该子控件的android:layout_row和android:layout_column属性即可,但是需要注意:android:layout_row=”0”表示从第一行开始,android:layout_column=”0”表示从第一列开始,这与编程语言中一维数组的赋值情况类似。

  最后,如果需要设置某控件跨越多行或多列,只需将该子控件的android:layout_rowSpan或者layout_columnSpan属性设置为数值,再设置其layout_gravity属性为fill即可,前一个设置表明该控件跨越的行数或列数,后一个设置表明该控件填满所跨越的整行或整列。




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值