9

Right now I am using MATCH_PARENT all throughout my app. I've decided to make the app available to Android 2.1 users but the MATCH_PARENT is not introduced till Android 2.2

How should I go about doing this if I want my app to use MATCH_PARENT when the Android version is 2.2 and above but use FILL_PARENT if it's 2.1 (or lower if I decide to open it to them later on)?

0xC0DED00D
  • 19,522
  • 20
  • 117
  • 184
bassicplays
  • 328
  • 1
  • 7
  • 21

3 Answers3

11

FILL_PARENT and MATCH_PARENT are same thing, if the version the user is having is 2.2 or higher FILL_PARENT would be replaced by MATCH_PARENT automatically. So it's better to use FILL_PARENT, to support backward compatibility.
There was a blog on Android dev site about this, I hope you can find it, if you want to have more details on this.

0xC0DED00D
  • 19,522
  • 20
  • 117
  • 184
  • 1
    Wow, I didn't know it gets replaced automatically. I thought if it's depricated you should avoid it at all costs. Thanks! – bassicplays Mar 30 '12 at 20:10
  • 1
    @dokgu What makes you think that _deprecated_ means that one has to _avoid it at all costs_? If that were the case, there would be no migration path. – class stacker Mar 04 '13 at 10:51
2

You shouldn't use fill_parent anymore even if you are supporting Android 2.1 or below. You may know that the Java compiler will convert constants like FILL_PARENT or MATCH_PARENT to their respective values statically in the class files. This also happens on layout XML files.

If you don't believe this, just try it on your emulator (you should declare android:minSdkVersion="4" in AndroidManifest.xml).

Spooky
  • 2,966
  • 8
  • 27
  • 41
mariotaku
  • 693
  • 1
  • 10
  • 26
2

Well they do the exact same thing, they just changed the syntax for 2.2+. I'd say just use FILL_PARENT always so that'll it always work if you plan on supporting 2.1 or lower.

Brayden
  • 521
  • 1
  • 5
  • 17