简体   繁体   中英

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

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 !

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

Your background should be like this

九个补丁背景

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

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM