FILL_PARENT and MATCH_PARENT

I am currently using MATCH_PARENT throughout my application. I decided to make the application available for Android 2.1 users, but MATCH_PARENT was not introduced until Android 2.2

How can I do this if I want my application to use MATCH_PARENT when the Android version is 2.2 and higher, but uses FILL_PARENT if it is 2.1 (or lower if I decide to open it later)?

+8
android android-layout backwards-compatibility
source share
3 answers

FILL_PARENT and MATCH_PARENT are the same if the version the user has is 2.2 or higher. FILL_PARENT will be automatically replaced by MATCH_PARENT . Therefore, it is best to use FILL_PARENT to maintain backward compatibility.
There was a blog on Android dev about this, I hope you can find it if you want to get more detailed information about it.

+10
source share

Well, they do the same thing, they just changed the syntax to 2.2+. I would say just use FILL_PARENT always so it always works if you plan on supporting 2.1 or lower.

+2
source share

You should no longer use fill_parent , even if you support Android 2.1 or lower. You may know that the Java compiler will convert constants, such as fill_parent or MATCH_PARENT , to their corresponding values ​​statically in class files. This also happens when placing XML files.

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

+2
source share

All Articles