How to support all the different resolutions of android products

你离开我真会死。 提交于 2019-11-27 13:17:55

You don't have to do that to support different densities. What you do is create different resources folders:

res/values-ldpi/dimens.xml
res/values-mdpi/dimens.xml
res/values-hdpi/dimens.xml

Then Android will decide which file to use. You can have something like:

<!-- in values-ldpi/dimens.xml -->
<dimen name="textSize">25dip</dimen>

and..

<!-- in values-mdpi/dimens.xml -->
<dimen name="textSize">20dip</dimen>

etc. And you shouldn't care about resolution... there are a lot of different resolutions sizes so it would be a hell to take decisions based on that.

Also, if you use dp instead of pixels, you hardly ever will have to create different dimensions files for each density. Of course, sometimes you have to, but it depends on the app.

Only thing you have to do is, that you set android:minSdkVersion to 7 or higher in your manifest file. Is is possible that some views will appear slightly different but app is applicable and on whole screen.

Now, i'm just guessing here since the rest of the implementation isn't shown, but I'm assuming you are using those derived measurements as px

Take a look at dp. That essentially does all those things you did, automatically, for any device. (Device Independent Pixel)

Don't worry about the slight difference in resolution: 540x960 is only slightly bigger than 480x800. The extra vertical space is easy: it gives you more room for your lists. For horizontal space, as long as you're handling your layouts correctly you'll simply have extra padding (30pix ea) on the sides.

Unfortunately, full-width images (480 wide) are a slightly bigger problem. If you want pixel perfect images, you'll want to use scaleType="center" so the image centers but not scales. If you want full width, you can use scaleType="fitCenter" to make it fill. It will be a bit fuzzy... but so many thing on Android are ;-)

I ran into this problem as well, except my app is a game where there is one SurfaceView canvas that I draw background images and sprites to (similar to LunarLander example).

The way you handle it here is to extend your background image to the largest size you are willing to support (540x960) but you keep all the important things (like buttons, text, information, etc) within a smaller rectangle of 480x800. You can extend the image itself, or just add borders. The key is that nothing important is there.

People with 480x800 phones will see your normal app. People with 540x960 phones will see a little extra border.

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