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

前端 未结 3 1984
情话喂你
情话喂你 2021-02-10 11:04

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 w

3条回答
  •  生来不讨喜
    2021-02-10 11:56

    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.

提交回复
热议问题