CQM
CQM

Reputation: 44278

Android nine-patch not being recognized on device

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" >

Upvotes: 7

Views: 6356

Answers (5)

Gyuri Majercsik
Gyuri Majercsik

Reputation: 2253

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

Upvotes: 6

Felix
Felix

Reputation: 1277

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

Upvotes: 1

Alexandre MOINE
Alexandre MOINE

Reputation: 235

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 !

Upvotes: 10

ubzack
ubzack

Reputation: 1876

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.

Upvotes: 3

inazaruk
inazaruk

Reputation: 74790

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

Upvotes: 4

Related Questions