tags:

views:

47

answers:

2

Hello

I was wondering if there is a way for using one set of images for all the resolutions. I have an application, and I want to port it on all the android resolutions but I don't want to store 3 sets of images, for every resolution category. What would be the best practice to use as less images as possible.

Thank you!

+2  A: 

Sure, you can provide only one set of images, in the base drawable directory, and Android will automatically resize as required.

This may result in aliasing and images that are not as clear as would be possible if you were to provide images sized properly.

Pierre-Luc Paour
+1  A: 

You probably mean density, not resolution (in Android, applications do not work directly with resolution).

Actually, you don't need to support all 3 densities. Quote from developer.android.com:

This pre-scaling mechanism works independently of the source. For instance, an application targeted for a high-density screen may have bitmaps only in the res/drawable-hdpi/ directory. If one of the bitmaps is a 240x240 icon and is loaded on a medium-density screen, the resulting bitmap will measure 160x160.

I've done simple test: removed ldpi and mdpi density images, launched my app on mdpi skin and it scaled hdpi images nicely. It's not the best practice, but android's prescaling does its part as described.

Please read this for more details.

Ralkie
Suppose I need to fill in my fullscreen app background with an image. I have distinct images for all possible resolutions (240x320...480x854). How can I consider density in this case? large, normal, and small qualifiers are not enough either, because 240x400 and 240x432 are both considered normal. To the moment I think of loading corresponding backround for current resolution manually.
southerton
That may be worth separate question :). Its a little bit unclear why you need different backgrounds for 240x400 and 240x432. If you would put 240x432 image in drawable-ldpi (and put it as fill_parent background for your root View), it would scale it to 240x400 automatically. But if different backgrounds really needed - I'm not aware of declarative way of doing that. And I think Android's API designers wrapped resolution (to size and density) for the reason.
Ralkie
I understand that I must put specific images in all 3 density folders in order to have an application that looks good on all densities. It would be better to put all the images in one folder, and at run time to be scaled proportional to the baseline configuration, but to have the same aspect ratio. Is this possible?
Gratzi