FILL_PARENT and MATCH_PARENT [duplicate]

北城以北 提交于 2019-11-28 07:21:59

问题


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)?


回答1:


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.




回答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.




回答3:


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).



来源:https://stackoverflow.com/questions/9949387/fill-parent-and-match-parent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!