android帧布局应用两种颜色,Android_深入Android 五大布局对象的应用,FrameLayout(帧布局),LinearLayout (线 - phpStudy...

深入Android 五大布局对象的应用

FrameLayout(帧布局),LinearLayout(线性布局),AbsoluteLayout(绝对布局),RelativeLayout(相对布局),TableLayout(表格布局)

FrameLayout:FrameLayout是最简单的一个布局对象。它被定制为你屏幕上的一个空白备用区域,之后你可以在其中填充一个单一对象 ,比如,一张你要发布的图片。所有的子元素将会固定在屏幕的左上角;你不能为FrameLayout中的一个子元素指定一个位置。后一个子元素将会直接在前 一个子元素之上进行覆盖填充,把它们部份或全部挡住(除非后一个子元素是透明的)。

android:layout_width="fill_parent"

android:layout_height="fill_parent"     >

android:text="button"

android:layout_width="fill_parent"

android:layout_height="wrap_content" />

android:text="textview"

android:textColor="#0000ff"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

右边图片常见为视频点播,两张图片叠放在一起,后一张覆盖前一张,添加链接到播放地址;

LinearLayout:LinearLayout以你为它设置的垂直或水平的属性值,来排列所有的子元素。所有的子元素都被堆放在其它元素之后,因此一个垂直列表的每一行只会有 一个元素,而不管他们有多宽,而一个水平列表将会只有一个行高(高度为最高子元素的高度加上边框高度)。LinearLayout保持子元素之间的间隔以 及互相对齐(相对一个元素的右对齐、中间对齐或者左对齐)。

LinearLayout还支持为单独的子元素指定weight。好处就是允许子元素可以填充屏幕上的剩余空间。这也避免了在一个大屏幕中,一串小对象挤成一堆的情况,而是允许他们放大填充空白。子元素指定一个weight值,剩余的空间就会按这些子元素指定的weight比例分配给这些子元素。默认的weight值为0。例如,如果有三个文本框,其中两个指定了weight值为1,那么,这两个文本框将等比例地放大,并填满剩余的空间,而第三个文本框不会放大。

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical"

android:layout_weight="1" >

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="hello,welcome to Livingstone's blog"

android:textSize="15pt" />    

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="horizontal"

android:layout_weight="2" >

android:layout_width="wrap_content"

android:layout_height="fill_parent"

android:layout_weight="2"

android:background="#aa0000"

android:gravity="center_horizontal"

android:text="red" />

android:layout_width="wrap_content"

android:layout_height="fill_parent"

android:layout_weight="1"

android:background="#00aa00"

android:gravity="center_horizontal"

android:text="green" />    

AbsoluteLayout:

AbsoluteLayout可以让子元素指定准确的x/y坐标值,并显示在屏幕上。(0, 0)为左上角,当向下或向右移动时,坐标值将变大。AbsoluteLayout没有页边框,允许元素之间互相重叠(尽管不推荐)。我们通常不推荐使用AbsoluteLayout,除非你有正当理由要使用它,因为它使界面代码太过刚性,以至于在不同的设备上可能不能很好地工作。

RelativeLayout:RelativeLayout允许子元素指定他们相对于其它元素或父元素的位置(通过ID指定)。因此,你可以以右对齐,或上下,或置于屏幕中央的形式来 排列两个元素。元素按顺序排列,因此如果第一个元素在屏幕的中央,那么相对于这个元素的其它元素将以屏幕中央的相对位置来排列。如果使用XML来指定这个layout,在你定义它之前,被关联的元素必须定义。

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical"

android:layout_weight="1" >

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="hello,welcome to Livingstone's blog"

android:textSize="15pt" />    

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="horizontal"

android:layout_weight="2" >

android:layout_width="wrap_content"

android:layout_height="fill_parent"

android:layout_weight="2"

android:background="#aa0000"

android:gravity="center_horizontal"

android:text="red" />

android:layout_width="wrap_content"

android:layout_height="fill_parent"

android:layout_weight="1"

android:background="#00aa00"

android:gravity="center_horizontal"

android:text="green" />    

TableLayout:

TableLayout将子元素的位置分配到行或列中。一个TableLayout由许多的TableRow组成,每个TableRow都会定义一个row(事实上,你可以定义其它的子对象,这在下面会解释到)。TableLayout容器不会显示row、cloumns或cell的边框线。每个row拥有0个或多个的cell;每个cell拥有一个View对象。表格由列和行组成许多的单元格。表格允许单元格为空。单元格不能跨列,这与HTML中的不一样。

android:layout_width="fill_parent" android:layout_height="fill_parent"

android:stretchColumns="1">

//这里是上图中的分隔线

//让TextView显示在右面

android:padding="3dip" />

相关阅读:

jquery自定义右键菜单、全选、不连续选择

jQuery的css()方法用法实例

基于JSP实现一个简单计算器的方法

Android获取应用程序大小的方法

jQuery插件简单实现方法

css background-position 用法详细图文介绍

Windows系统怎么快速批量添加字体?

Android中自定义进度条详解

JS使用cookie设置样式的方法

Android加载View中Background详解

Android 搜索SD卡文件的开发示例

通过Jquery.cookie.js实现展示浏览网页的历史记录超管用

css+js实现的网页常见选项卡效果

解析Linux下Varnish缓存的配置优化

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值