Android布局中match_parent和fill_parent的差别

今天在做项目的一个新功能的时候,从网上查找资源,发现android2.2中出现的MATCH_PARENT感到不明确。过去仅仅有FILL_PARENT和WRAP_CONTENT那么match_parent究竟是什么类型呢?


经过一番研究发现,从Android 2.2開始FILL_PARENT改名为MATCH_PARENT ,从API Level为8開始我们能够直接用MATCH_PARENT来取代FILL_PARENT,他们的定义本质是一样均为-1。仅仅是换了个别名,可能为了更准确些,比方终于在SDK中的定义为:


fill_parent   -1  The view should be as big as its parent (minus padding). This constant is deprecated starting from API Level 8 and is replaced by match_parent. 
match_parent   -1 The view should be as big as its parent (minus padding). Introduced in API Level 8. 
wrap_content   -2  The view should be only big enough to enclose its content (plus padding). 


从Android 2.2開始fill_parent改名为match_parent,从API Level 8能够直接用match_parent来取代fill_parent,只是2.2以后的版本号fill_parent仍然能够使用,他们的含义都是一样的,都是填满整个父窗体


三个属性都用来适应视图的水平或垂直大小,一个以视图的内容或尺寸为基础的布局比精确地指定视图范围更加方便。


1)fill_parent


设置一个构件的布局为fill_parent将强制性地使构件扩展,以填充布局单元内尽可能多的空间。

这跟Windows控件的dockstyle属性大体一致。设置一个顶部布局或控件为fill_parent将强制性让它布满整个屏幕。


2) wrap_content


设置一个视图的尺寸为wrap_content将强制性地使视图扩展以显示所有内容。以TextView和ImageView控件为例。设置为wrap_content将完整显示其内部的文本和图像。布局元素将依据内容更改大小。

设置一个视图的尺寸为wrap_content大体等同于设置Windows控件的Autosize属性为True。


3)match_parent
   Android2.2中match_parent和fill_parent是一个意思 .两个參数意思一样。match_parent更贴切。于是从2.2開始两个词都能够用。

那么假设考虑低版本号的使用情况你就须要用fill_parent了

原文地址:https://www.cnblogs.com/claireyuancy/p/7241468.html