I am brand new to Android
and I am using Eclipse ADT
to create a simple application. This application has a button that changes it's background image based on user clicks.
I noticed that there are 4 folders for images in my project: drawable-hdpi, drawable-ldpi, drawable-mdpi, and drawable-xhdpi
.
and I also noticed that the images that are in there currently (the launcher icon) are all different sizes.
Does this mean that I have to use some image editing software to create one image for each resolution for each of my images? Or (hopefully) is there a way to import an image and have this done for me automatically?
Thanks!
Images and other visual files are stored in one or more drawable directories. If only in one directory, Android will scale the image as needed. If more than one directory is used, Android will select the appropriately sized image.
(Side note: XML files can also be written and stored as drawables. These kinds of files can control when multiple images are to be used based on the state of a view, or other visual settings like gradients, borders, etc.)
So, what should you do?
For best results (from the Android developer docs):
To generate these images, you should start with your raw resource in vector format and generate the images for each density using the following size scale:
This means that if you generate a 200x200 image for xhdpi devices, you should generate the same resource in 150x150 for hdpi, 133x133 for tvdpi, 100x100 for mdpi, and finally a 75x75 image for ldpi devices.
If you just want to use one image and let Android scale for you:
More than 75% of Android devices now have hdpi or greater resolutions, according to the Dashboard on the Android Developer site. So if you create one image at hdpi, for example, it will look perfect on about a third of devices, scale up for some, and scale down for about 25% of devices. In general I think you'd be better off scaling down than scaling up, too.