9-patch - 1px border blurred

I am testing HTC Desire, which is an hdpi device. The problem is obvious when viewing the image:

9-patch - 1px border is blurred

And this is what my 9-patch looks like (made with the standard 9-patch tool):

9-patch - 1px border is blurred

The left image is my photoshop file, and the right one is a screenshot from my device. As you can see, there is a huge difference. Let's say that the shadow is not so important, but the blurry border looks bad.

Is my 9-patch png wrong? What can I do to achieve a clear solid border of 1px?

+6
source share
2 answers

You need to use a tool with 9 paths for each png in a different drawable folder. Sometimes the problem is that Android is trying to convert png and blur the black lines, which causes a later problem when displayed correctly.

+8
source

To work around this problem, simply place patch 9 in the drawable-no-dpi folder. This allows you to have one image for all densities. And Android will not touch the image.

This is basically what I do for my projects, if I really don't want to have a difference between densities. In this case, I create one 9 patch for density.

Alternative solution:

Compress your top and left markers by 1 pixel on each side. This ensures that the scalable part does not overlap the gray border.

+5
source

Source: https://habr.com/ru/post/915408/


All Articles