Android: 9-patch png is treated like a normal png - android

I've made this 9-patch png and added it to the res/drawable folder:
It works nice in the example eclipse shows:
But on the emulator it looks messed up:
Why is this happening and how can I fix this?
EDIT: The border on which I've placed the black dots is white, not transparent. Not sure if that's got anything to do with it...

This probably happens because you have a small mistake with the black pixels you have set.
Try to re-cut the edges of the picture and to add the black pixels all over again.
I had this problem too once and this helped me.
if the border is white then this is your problem it has to be pure black or nothing at all.
UPDATE: Try this image:

It seems you are not saved your image with .9.png
In order to make it work do like this
save your image in the following format in your drawable folder
yourimage.9.png (not png format of your image)
Check this reference draw 9 patch

The Android SDK contains a 9-patch editing tool (draw9patch.bat) that can help you to produce and/or validate 9-patch images. Without it, it is very easy to make a mistake in defining your border.
The one-pixel border should be transparent except for the black pixels that define the various parts of the image to be treated differently during scaling.

Related

9patch (nine-patch) image does not stretch /scale properly

Dear Fellow Developers,
I've ran into the problem shown in the attached picture. We have been trying to tweak the dropdown menu's 9patch image provided by a graphics designer, but could not get it to work. The black stretch markers are not being hidden, and Android does not stretch it the way we would expect.
The device is a Nexus 7. We have tried several various image sizes, but none seemed to work. I am also attaching a copy of the 9patch.
What could be wrong?!
This happens:
Here is the 9patch
If the image has been created in a normal image editor rather than the android 9 patch tool, it could be just that its not done exactly right.
The image must have a 1px transparent border other than where the black lines are. Make sure its completely transparent and is only 1 px thick
Also I don't think you can have split lines (like you have down the left and right side of the image, I think they must be one solid line on each side)

Device doesn't recognize 9 patch

I made some 9 patch images to use as a button, but the device doesn't recognize them.
9 patch image:
How eclipse shows it:
How my device shows it:
As you can see, the english button has two black pixels at the top and slovenian only has one. I did this to try if two pixels would work, but it still didn't.
I'm pretty sure I did everything right. Names are in the right format (name.9.png)
Your problem is that your right border is not continuous. The right border defines the padding, and must be a continuous line (or a single pixel). You seem to simply have the logic inverted, but it should be like this instead:
9-patch images have to be pre-compiled, when the one pixel border is removed and encoded to a PNG chunk. Your image is not being pre-compiled. That's why the black pixels still appear, and the image is not being correctly stretched.
Make sure your images are in one of the drawable folders, and their name ends with .9.png. If everything is right, try to clean and build your project.

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:
And here is how my 9-patch (made with standard 9-patch tool) looks (zoomed):
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?
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.
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.

9patch border black pixels visible

I need express help with 9 patch. I run draw9patch and change and save as name.9.png and save at res/drawable ( later tried in res/drawable-hdpi but didn't help) but problem is when I show on devic/emilator it doesn't strech and that black pixels at border are still visible ( I thought it is visible only inside 9patch for creating intersection ). Can somebody told me what is wrong ? I saved as name.9.png but it seems like it not recognize like 9.patch
Ensure transparency is not set in the outer pixel border that sets the patches. The Draw9Patch tool accepts it so it looks correct but it never actually works in my experience.
Ensure your 9patch image is named like this: imageName.9.png

Draw 9-patch not working - cannot edit image

after I found out (sadly) that there is no easy way to create a simple border around a View, I was forced to use the 9-patch-image approach to get a border around my View.
So I read the short thing there is on the 9-patch and its easy enough to understand. I started the "Draw 9-patch" application that came with the Android SDK, opened up a very simple image I created in Paint and then... I got stuck.
According to the page (http://developer.android.com/guide/developing/tools/draw9patch.html) I should be able to define those areas where the image can be expanded and so on, just by clicking on the edges ("Click within the 1-pixel perimeter to draw the lines that define the stretchable patches...").
So I try to do just that and absolutely nothing happens. I try to hold down SHIFT when clicking and also do the rigth-mouse-click, and nothing happens. When I move the mouse away from the 1-pixel perimiter I get a grey-and-red "marquee" (stripes).
Bottom line is: nothing happens no matter what I do.
The tool definitely works, but make sure the image you create first does NOT have the .9.png extension. If it does, the draw9patch tool will assume the 1 pixel perimeter of your image is already setup as 9-patch. If you open an image with just a .png extension, the tool will add the 1 pixel perimeter and you will be able to manipulate it as described, and save it as 9-patch when you're done.
The 9-patch tool is a bit awkward to use, but it does work. I believe you need to left click and drag around the edge to paint the outside border.
Alternatively, you can use any image editor and create a one pixel empty border around it, and draw in the following:
Top/Left = black pixels for the area of the image that can be grown or shrunk as needed. For a typical border, it is everything except for the curved corners
Bottom/Right = black pixels for the small snippet that should be repeated if the image needs to be grown in that direction.
You must use a non-8bit png file to create a .9.png file, or it can not be edit.
In my case, I can convert a 8-bit png to 9-patch file with Android Studio successfully, but I can't edit it anyway.
When I export the origin psd to normal png file, and convert it to 9-patch file, the 9-patch borders ban be edit now!

Categories

Resources