Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

9-patch - 1px border is blurred

I'm testing on HTC Desire which is a hdpi device. The problem is clear when you look at the image:

9-patch - 1px border is blurred

And here is how my 9-patch (made with standard 9-patch tool) looks (zoomed):

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 THAT important, but the blurred border looks bad.

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

like image 974
Michał Klimczak Avatar asked May 10 '12 14:05

Michał Klimczak


2 Answers

You should use 9-path tool for each png in different drawable folder. Sometimes problem is this the Android try to convert the png and blur the black lines, what cause later problem with properly displaying.

like image 110
goodm Avatar answered Nov 03 '22 11:11

goodm


To circumvent this problem simply drop the 9 patch inside the drawable-no-dpi folder. This allows to have one image for all densities. And android won't touch the image.

This is mostly what I do for my projects, unless I really want to have a difference between the densities. In that case, I create one 9-patch per density.

Alternate solution:

Shrink your top and left markers by 1 pixel on each side. This will ensure that scalable part does not overlap the grey border.

like image 5
Richard Lalancette Avatar answered Nov 03 '22 11:11

Richard Lalancette