-8

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.

Community
  • 1
  • 1
App Kart
  • 924
  • 2
  • 13
  • 24
  • 6
    Oh no, not this question again! http://stackoverflow.com/questions/9949387/fill-parent-and-match-parent ; http://stackoverflow.com/questions/10854717/why-did-match-parent-replace-fill-parent ; http://stackoverflow.com/questions/8516825/is-deprecated-word-the-only-difference-between-fill-parent-and-match-parent ; http://stackoverflow.com/questions/7608196/android-fill-parent-to-match-parent ; http://stackoverflow.com/questions/5761960/what-is-the-difference-between-match-parent-and-fill-parent-property-in-android – davidcesarino Jun 28 '12 at 03:35

3 Answers3

13

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"

K_Anas
  • 31,226
  • 9
  • 68
  • 81
  • 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)....can u explain with example. – App Kart Jun 28 '12 at 03:28
  • 2
    using `match_parent` will not throw an error no matter what version of Android you are targeting... – Alex Lockwood Jun 28 '12 at 03:31
  • @ArunKumar match_parent is only a name convention that Google developer has adopted for api 8 and higher!! – K_Anas Jun 28 '12 at 03:33
  • so that there is no difference between them.then why google changed it? – App Kart Jun 28 '12 at 03:35
  • 1
    What was wrong with `fill_parent` was that it didn't actually *fill* the parent, but instead it made it have the same dimension as the parent... or in other words, it *matched* the parent dimension. – Alex Lockwood Jun 28 '12 at 03:35
  • @ArunKumar I remember that Roman Guy 5Google Devveloper)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" – K_Anas Jun 28 '12 at 03:36
  • (minus padding) what does means?child have minus padding according to parent or something else. – App Kart Jun 28 '12 at 03:37
  • @ArunKumar, you are no longer asking about the difference between the two... instead you are asking about its actual behavior. The answer to your original question is that *there is no difference at all*. – Alex Lockwood Jun 28 '12 at 03:38
  • @ArunKumar padding right for exemple is space between a right widget border and the right parent layout border – K_Anas Jun 28 '12 at 03:40
  • its fine for me.but i want to explain with two explain one is for fill_parent and another for match_parent.if u can help me.because lot of things is only writing not explain with explain.i already know these above line but i am not understand.i know it works as same. – App Kart Jun 28 '12 at 03:41
  • @AlexLockwood don't forget to use the @ because in your last comments ArunKumar don't get notification of your comments, and congrats for the 10K :D – K_Anas Jun 28 '12 at 03:42
  • @K_Anas, `static final` constants are compiled into the byte code when the `.apk` is compiled and thus, Android will not perform a dynamic search for a value represented by `match_parent` at runtime. In fact it will know nothing about the variable `match_parent` that represented the `-1`. This is why an error isn't thrown in Android 2.1 and lower – Alex Lockwood Jun 28 '12 at 03:42
  • @K_Anas, (didn't forget it that time :D). And thanks lol... but still 10,000 points more to go haha -_- – Alex Lockwood Jun 28 '12 at 03:43
  • @AlexLockwood:yes you are right i want to exact behavior? – App Kart Jun 28 '12 at 03:46
  • @AlexLockwood, sorry but i don't think so but this constant doesn't figure in low API version i tried it and it throws an error when declaring it in Xml – K_Anas Jun 28 '12 at 03:47
  • @ArunKumar, both `match_parent` and `fill_parent` will stretch the size of the view to match the same size as its parent view. – Alex Lockwood Jun 28 '12 at 03:50
  • when go to before 2.2 then it throw exception. – App Kart Jun 28 '12 at 03:50
  • @K_Anas, sorry I misunderstood what you meant. yes you are right... an error will be thrown because `match_parent` isn't defined in the earlier SDK versions. What I meant to say is that you can use `match_parent` in newer APIs and be certain that older devices will won't crash for not "recognizing" the value (since they are compiled into the byte code). – Alex Lockwood Jun 28 '12 at 03:52
  • yes fill_parent can be used for low api and higher but match_parent is for api 2.2 and higher – K_Anas Jun 28 '12 at 03:52
  • @AlexLockwood yes that's right – K_Anas Jun 28 '12 at 03:56
  • i understand @Tanis.7x answer with explain with exmple.actually fill_parent is same as match_parent because child view is not filling space instead of it matches according to parent viewgroup.actually we should use fill_parent because it also run before 2.2.its good for us. – App Kart Jun 28 '12 at 03:59
2

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)

Alex Lockwood
  • 83,063
  • 39
  • 206
  • 250
  • so why google change it?there is some reason behind it. – App Kart Jun 28 '12 at 03:29
  • i am agree but actually can u explain with layout. – App Kart Jun 28 '12 at 03:33
  • the reason they changed it is because the android team thought `fill_parent` was a misleading name... they felt the name `match_parent` better suited its actual behavior. – Alex Lockwood Jun 28 '12 at 03:34
  • What was wrong with `fill_parent` was that it didn't actually *fill* the parent, but instead it made it have the same dimension as the parent... or in other words, it *matched* the parent dimension. – Alex Lockwood Jun 28 '12 at 03:36
2

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.

Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120
  • Say you have a vertical `LinearLayout` with two added `TextViews`, each with `height: "wrap_content"` and `width: "fill_parent"`. With `fill_parent`, some may expect that the two TextViews will appear side-by-side, collectively expanding to fill the LinearLayout. In reality, those views are **matching** their parent's width, and will stack vertically. – Bryan Herbst Jun 28 '12 at 03:35
  • this example what i want.Thanks Tanis.7x once again. – App Kart Jun 28 '12 at 04:01