Search code examples
androidnine-patch

Create simple 9 patch image that keeps logo in centre


I am trying to create a simple 9-patch image that keeps the image in the centre.

The logo I am using is similar to this:

Example logo

The stretchable regions would of course be the sides and the top. The static region would the be the logo itself.

The tool I am using is the following: https://romannurik.github.io/AndroidAssetStudio/nine-patches.html#&sourceDensity=320&name=example

Unfortunately, no matter how much I try I just can't seem to get this right.

I can easily make the logo stay on the top right, but not in the centre.

How do I get it so the logo stays in the centre?

Can someone show me how to achieve my desired behaviour. A screenshot will be ideal!


Solution

  • It turns out it was not possible using that tool as you can only place 2 stretchable regions.

    Instead I used the tool provided by the android sdk located at:

    path-to-android-sdk/tools/lib/draw9patch.jar
    

    The above tool allows you to state multiple stretchable regions.

    You need 4 to achieve the centre behabiour.

    One on either side of the top edge and one on either side of the left edge.