对mars-droid第二季第三集视频的小问题的修正

2011-09-06

今晚看到mars老师第二季第三集的视频,在看到第11分钟时,mars老师说到了设计宽高的一个参数match_parent的问题,这让我想起了之前自己的笔记。
  mars老师以为这是谷歌文档的讹误,并说他自己试过,报错。我不知道这个问题mars老师后来有没有修正,在这里我贴出我的笔记如下,因为就这个问题,我曾经特意翻过Android的文档。

FILL_PARENT
MATCH_PARENT
WRAP_CONTENT

在看mars老师的第一季视频中,在xml布局文件中设置layout_width及layout_height常用的是fill_parent和wrap_content。前者表示与父控件减于内边距后一样大小,后者表示与它的内容一样大小。
在由工具生成的android的xml文件中,有match_parent。查了文档,注释如下:
public static final int FILL_PARENT 
Since: API Level 1 Special value for the height or width requested by a View. FILL_PARENT means that the view wants to be as big as its parent, minus the parent's padding, if any. This value is deprecated starting in API Level 8 and replaced by MATCH_PARENT. 

Constant Value: -1 (0xffffffff) 

public static final int MATCH_PARENT 
Since: API Level 8 Special value for the height or width requested by a View. MATCH_PARENT means that the view wants to be as big as its parent, minus the parent's padding, if any. Introduced in API Level 8. 

Constant Value: -1 (0xffffffff) 

public static final int WRAP_CONTENT 
Since: API Level 1 Special value for the height or width requested by a View. WRAP_CONTENT means that the view wants to be just large enough to fit its own internal content, taking its own padding into account. 

Constant Value: -2 (0xfffffffe) 

第一个与第二个的注释貌似一样,但是第一个在最后一句话中说,fill_parent在api8的平台之后就开始弃用,并使用match_parent替代。

显然从上面段落的最后一句话,我们能猜到,mars老师之所以使用match_parent不灵验,大概与他所选的Android平台有关,因为match_parent是自api8之后才开始替代fill_parent的。并且从文档中,我们也可以看到,这两个的值是一样的,都是-1(0xffffffff)。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值