parent in android

Possible Duplicate:
what is the difference between match_parent and fill_parent property in android
FILL_PARENT and MATCH_PARENT

I have go through android developer site where they give following difference :

Note: Beginning with Android 2.2 (API level 8), "fill_parent" has been renamed "match_parent" to better reflect the behavior. The reason is that if you set a view to "fill_parent" it does not expand to fill the remaining space after sibling views are considered, but instead expands to match the size of the parent view no matter what—it will overlap any sibling views.

But anyone explain with example.so that things may clear.


They're the same thing (in API Level 8+ ). Use match_parent.

fill_parent (renamed MATCH_PARENT in API Level 8 and higher), which means that the view wants to be as big as its parent (minus padding)

fill_parent : 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

For Android API 1.6 to 2.1 match_parent will throw you an error, so use fill_parent in these cases. To support backward compatibility, it's better to use fill_parent

I remember that Roman Guy (Android Developer at Google) said, that they have changed the name because "fill_parent" was confusing for developers. As matter of the fact, "fill_parent" does not fill the remaining space (for that you use the weight attribute) but it takes as much space as its layout parent. That's why the new name is "match_parent"


Both are static final constants that represent the value -1 . They are hard coded into the byte code when you compile your .apk , so there is no difference and are both completely compatible with all Android SDK versions.

You'll see that they both represent the same value in the documentation:

public static final int FILL_PARENT

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

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)


The clarification is this:

  • Fill parent implies (or could imply) that multiple side-by-side views would expand to completely fill their container. Thus one might think that two views with "fill_parent" added to a parent view would both resize to 50% of the parent's size.
  • Match parent is clearer, as setting a view to fill_parent actually sets the size to the container's size.
  • As other users stated (and as the documentation states), this is purely a change to make it more obvious what the outcome of using "fill_parent" will be.

    链接地址: http://www.djcxy.com/p/85348.html

    上一篇: compileSdkVersion和targetSdkVersion有什么区别?

    下一篇: 家长在android中