73

I found that both fill_parent and match_parent means the same thing

  • fill_parent means that the view wants to be as big as its parent, minus the parent's padding, if any.
  • match_parent means that the view wants to be as big as its parent, minus the parent's padding, if any.

The only difference that I found is that fill_parent is deprecated starting from API Level 8 and is replaced by match_parent

However, I didn't notice any difference between these two. If both are the same then, why is fill_parent deprecated. Can anyone explain any differences between these two except for the fact that one is deprecated and the other isn't?

I have gone through http://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html

Community
  • 1
  • 1
Sunil Kumar Sahoo
  • 53,011
  • 55
  • 178
  • 243
  • Having two methods in the API which do the same thing is one reason to deprecate a method. – fyr Dec 15 '11 at 08:01
  • More on this http://stackoverflow.com/questions/5761960/what-is-the-difference-between-match-parent-and-fill-parent-property-in-android – vnshetty Dec 08 '12 at 04:42

4 Answers4

95

As you said they are exact the same. As Romain Guy said, 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".

Robert Martin
  • 16,759
  • 15
  • 61
  • 87
gwvatieri
  • 5,133
  • 1
  • 29
  • 29
9

According to Romain Guy in this video, these words mark the same behaviour. But many developers misunderstood what fill_parent meant, hence they came up with an alias.

Zsombor Erdődy-Nagy
  • 16,864
  • 16
  • 76
  • 101
7

I have developed in Android long enough to also realize that there seems to be no difference except when you want to run on an older API. I would use fill_parent because I make all of my apps with minimum API 7. Also, on a side note, since Android is forward compatible this is the way to go.

c_idle
  • 1,448
  • 4
  • 22
  • 40
4

Addition to the existing answers. Here is a part of the source code from LayoutParams class, both FILL_PARENT and MATCH_PARENT constants map to the same value. So we have absolutely the same functionality.

    public static class LayoutParams {
    /**
     * 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 {@link #MATCH_PARENT}.
     */
    @SuppressWarnings({"UnusedDeclaration"})
    @Deprecated
    public static final int FILL_PARENT = -1;

    /**
     * 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.
     */
    public static final int MATCH_PARENT = -1;
    ...
mes
  • 3,581
  • 29
  • 28