9-patch - 1px border is blurred
Asked Answered
D

2

6

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?

Doss answered 10/5, 2012 at 14:48 Comment(10)
You must do something when you using the 9-path tool. Are you using 9-path tool for each png in different drawable folder?Astrahan
Is your 9-patch named correctly as filename.9.png?Kucik
instead of line just put an dot in four sides of your image in draw9patch. it will work.Raeleneraf
It's named correctly and it mostly looks good. But I put it in drawable, not drawable-hdpi. Is that what causes the problem? I mean, it would be the same image in every folder (drawable, drawable-mdpi, drawable-hdpi etc). Does android treat them differently anyway?Overplus
@Padma Kumar. Already tried, doesn't work, but thanks for contributingOverplus
@goodm, it was the problem with the wrong folder. Please write your answer so I could give you your well earned reputation:) Btw it's not really clear to me why it should be in different folder even if it's the same image, if you know, please clarify.Overplus
@MichałK for draw9patch image no need to put that in specific folder you can put that in normal drawable folder.Raeleneraf
Well I did. And that caused the problem. Then I put it in the right folder (drawable-hdpi) and it workedOverplus
If you only want one copy, put it in the drawable-nodpi folder.Immunology
Sounds like a nice solution, will try it later, thanks:)Overplus
A
8

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.

Astrahan answered 10/5, 2012 at 15:32 Comment(0)
S
5

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.

Sharecropper answered 17/9, 2012 at 23:18 Comment(1)
Yep, that was the solution if you don't put every drawable in different dpi (as you can see in these old comments).Overplus

© 2022 - 2024 — McMap. All rights reserved.