I'm not the most advanced Android programmer yet but I have picked up a few things ever since I started to create my first basic apps for the platform. While it is possible to add a single png image as a resource to an Android project, it is also possible to use multiple versions of that same image instead. If there is only one image, it will be used regardless of the screen size and density of the Android device it runs on. The system scales and resizes images automatically if the need arises so that the application works on different screen sizes and densities if no matching image resource can be located. While that is better than not displaying images at all, it may lead to all kinds of issues including images that do not really look that good on particular devices.
The Android developer guide has a large page dedicated to images, screen sizes, density and all that good stuff. If you want to add multiple versions of the same image to your Android app, you need to know how to create those. While you can theoretically use any image editor or resizer for the task, you may want to check out the 9Patch Resizer tool instead which has been designed for exactly that task and automated so that you do not have to juggle around with values on your own.
So, instead of having to create multiple versions of the same image manually you simply create one version - the xhdpi version - and use the program to get all the other image versions created for you. You can repeat that process for all the images that you include in your application.
The program is available as an executable file for Windows and as a Java jar file for other operating systems. The executable file displays a basic interface that you can drop your xhdpi image in to. When you do, it will automaticlaly created the respective drawable-hdpi, drawable-ldpi and drawable-mdpi folders in the same root directory the image is stored in so that you can move them into your Android app project folders right away to include them in your application.Advertisement
Ghacks is a technology news blog that was founded in 2005 by Martin Brinkmann. It has since then become one of the most popular tech news sites on the Internet with five authors and regular contributions from freelance writers.