Search code examples
androidnine-patch

Image with Centered Text (part of the image) in 9 patch?


I am trying to create a 9patch png for a button in Android using an image with some static text and an icon in it. I used the 9 patch tool in the sdk but when I try to use the resulting png, I get malformed 9patch errors. Here is an image of what it looks like in the 9 patch editor...

9Patch editor

Is this scenario possible or(is it because I have too many patches) or is my issue something else?


Solution

  • Basically what I discovered is that although possible, there are better solutions (the one mentioned above and described in more detail below)

    I ended up going with the solution mentioned in the comment above. Creating a nine patch of the background/gradient and then floating the icon on the left and putting text as a property of the button itself. Works well enough!

    As noted below by the commenter, this actually is possible as long as you don't have broken lines on the right or bottom of the 9patch... So If you took my above image and just removed the two lines on the bottom right side and the right bottom, it works like a charm (I'm still going to go with the other option however)