Search code examples
androideclipsenine-patch

9 patch isn't working on device


I'm trying to make a 9 patch image to be a header of my application but it doesn't work.

This is the image:

enter image description here

As you can already imagine, I want only the middle (blank) part to be streched and nothing else. It works normally in eclipse screen preview but it stretches it as if it wasn't 9 patch when i run it on my device.

I've had problems like this before so I'm clearly doing something wrong with 9 patches, I looked up a lot of info and tutorials on 9 patches and I just don't seem to get it. Could someone give me a good explanation where exactly to put the black dots for it to work and why?


Solution

  • When you put those extra lines in an image, they work like this:

    • Top and Left extra lines define the vertical and horizontal pixels which will be stretchable (the intersection is called stretchable area).
    • Bottom and Right extra lines are optional and define the padding. In this case, the intersection is the region in which the content will be placed (the rest is the padding).

    enter image description here

    I recommend you to use the 9 Patch editor included with the Android sdk. It is called draw9patch and can be found at <android-sdk-root>/tools. You will be able to see a preview of your image with 9patch.

    enter image description here

    Links: