Android nine-patch not being recognized on device
Asked Answered
H

5

7

I just made a nine-patch

it is saved like border.9.png from the draw 9 patch tool.

in my android layout editor, it shows up like it is going to be a proper 9 patch graphic, stretched out yet not pixelated.

yet on a real device, it just shows a giant stretched image, with the 9patch guides seen, it looks really bad

whats going on??? and how do I fix it

my xml:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/border"
        android:orientation="vertical"
        android:padding="35dip" >
Heads answered 12/12, 2011 at 19:49 Comment(0)
D
6

You can find all the necessary information how to create a 9.patch here

Your background should be like this

nine patch background

Note: the markers to the bottom and right need to be drawn as complete lines, not single dots.

Edit
Seems that uploading the 9.patch here becomes altered, and cannot be used as a 9.patch anymore.
You can download the functional version from here

Detail answered 12/12, 2011 at 20:7 Comment(1)
Thanks! I get it now, I had to tweak it again but it worked for me!Heads
D
10

I just had the same issue : everything worked fine in Eclipse but all where streched on the device. I solved it by opening the PNG in the Draw 9-patch tool. Just open the png and save it et voila !

Dedicated answered 19/3, 2012 at 22:49 Comment(1)
+1. This is exactly what happened to me. The 9-patch PNGs I was given did not work properly on simulator/device until I opened/saved them in the Draw 9-patch tool (despite they looked Ok in GUI layout builer). Magic.Cyprus
D
6

You can find all the necessary information how to create a 9.patch here

Your background should be like this

nine patch background

Note: the markers to the bottom and right need to be drawn as complete lines, not single dots.

Edit
Seems that uploading the 9.patch here becomes altered, and cannot be used as a 9.patch anymore.
You can download the functional version from here

Detail answered 12/12, 2011 at 20:7 Comment(1)
Thanks! I get it now, I had to tweak it again but it worked for me!Heads
H
4

This looks like invalid 9.ptach file to me. There should be solid regions at the bottom and on the right side.

Haydeehayden answered 12/12, 2011 at 20:7 Comment(1)
+1 works for me: single dots as content markers look fine in the draw9patch utility and in the ADT Layout editor, but to work on the device, the content markers (bottom and/or right) need to be drawn as one complete line.Beneficial
F
3

As a last resort, whenever you're having a tough time getting a 9 patch to be recognized as such, I find it's always best to just make a BRAND NEW image file in your imaging software, copy all except the 4 1-pixel borders of your original image, then paste into your new image file. Sometimes no matter how much you delete away the 4 edges, the device/emulator still can't recognize it as a 9-patch, even though (and this should probably be of concern to the Android SDK dev team) it's a perfectly fine 9-patch in Eclipse's Graphical Layout.

Also note, black lines on the right and bottom edges are optional. They specify "padding", in particular the region where the content (the child of the parent with the 9-patch background) fits.

Firry answered 12/1, 2012 at 21:54 Comment(0)
C
1

It took me some hours to figure out, why my nine patch didn't render right.

The reason was quite simple. My nine patch image was stored under:

/res/drawable

instead of

/res/drawable-xxx
Celeski answered 6/6, 2012 at 11:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.