How to use 9 patch images in android for different-2 densities(like mdpi,ldpi,hdpi).?

Arun Badole picture Arun Badole · Sep 28, 2011 · Viewed 7k times · Source

I am creating an android application in which I want multiple screen support.For these I have used 9 patch images.

But my question is this whether using 9 patch images will be enough for different-2 density's devices or I will need to create different-2 9 patch images for varying densities(like mdpi,ldpi,hdpi).

Thanks in advance

Answer

rfgamaral picture rfgamaral · Oct 4, 2011

I recently found out myself in the same situation so let me pitch in and expand on what has been said already...

Yes, 9-patch images will scale, that's what they exist for. But if you should use a 9-patch image for all screen densities, that depends on the image really. 9-patch images are more commonly used, for instance, buttons. You can have different sized buttons in your app and a 9-patch image will help deal with them, no matter how you size your button (as long as the 9-patch image is properly created).

But let's say your button design has some really round corners for the hdpi version. You create your 9-patch image without messing the corners but when you look at it in the ldpi version, you'll realize your corners are too big for that low resolution. For this situation, you'll need a different 9-patch image with less round corners, that look better on that resolution.

So, the final answer is, it really depends on your image. If you can create a 9-patch image that looks good in all densities, than fine, use it, as you only need one image to handle all densities. But if it doesn't look good, because of corners, gradients, or whatever, than you'll need one 9-patch image for each screen density.

Hopefully it's clearer now.