I am new to android development and I've been reading up on how to correctly include image assets in my application. Various articles (including the android developer guide) describe including multiple images to target different screen sizes by placing them in convention-based resource folders.
Although the system scales your layout and drawable resources based on the current screen configuration, you may want to make adjustments to the UI on different screen sizes and provide bitmap drawables that are optimized for different densities.
However, this implies that it is not always necessary to include multiple images targeting different screen sizes.
If I include a single image of sufficient size for a large screen then the system should scale this down for smaller screens without suffering any pixilation or loss, right? I would have thought this approach also reduces the overall payload of the application since there are less graphics files being bundled into the app.
I appreciate that there may be instances where app designers may want to tailor individual graphics per screen size but for a general case is the single-file approach a more appropriate strategy? What are the drawbacks of not providing density-specific graphics?
Normally you should provide drawables for at least:
mdpi
hdpi
xhdpi
xxhdpi
ldpi
is pretty much irrelevant nowadays since barely any devices exist that still fall in that category. Normally you also don't need anything above xxhdpi
. It is possible to just provide the xxhdpi
drawables and Android will scale them for the other densities, but that is not perfect. There might be some pixelations or generally lower image quality. If you want good results you need to provide drawables in all relevant densities.
If you were somehow unable to provide images for lower densities - which I have to emphasise again should be avoided if at all possible - you can help Android to scale the images correctly by only using sizes and in your layout that are easily divisible by 8, 4, and 2. For example instead of using 10dp
you would use 8dp
or 12dp
. Using sizes that are only divisible by those three factors would in fact be best practice.
There are a few tools to assist you with properly scaling the drawables. Namely the image resizer tool that comes with the SDK and the Android Asset Studio.
I am sure you already read it, but here is the link to the relevant documentation.
EDIT: Since you mentioned that one can keep the APK smaller by not including the images of lower densities: You have to remember the drawables for the highest density make up the majority of the size of your APK. Not including the ones for lower densities has really not that much of an effect on APK size.