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.
- drawable-ldpi - Low density images
- drawable-mdpi - Medium density images
- drawable-hdpi - High density images
- drawable-xhdpi - Extra high density images (i.e. retina-like displays)
- drawable-xxhdpi - Extra extra high density images (devices like Nexus 10, Samsung Galaxy S4, HTC One and Sony Xperia Z)
- drawable-xxxhdpi - Triple extra high density images (Nexus 6 and 9)
(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:
- xxxhdpi: 4.0
- xxhdpi: 3.0
- xhdpi: 2.0
- hdpi: 1.5
- tvdpi: 1.33 (TVs only)
- mdpi: 1.0 (baseline)
- ldpi: 0.75
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.
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?
If you already have high resolution sources (or vector graphic formats) of your images, you can use the Android Asset Studio to generate icons/images from your own source images for every density (minus xxhdpi). You can also create icons/images from default Android clipart, that can be themed for various versions of Android. This will save you some of the hassle of resizing and saving with an image editing tool.