Search code examples
androidimagenine-patch

Making 9 patch image from ribbon icon doesnt strecth correctly


I got this image and i need to make 9 patch of it (i am using it for textview background). enter image description here

I need the text to appear text to left of star like this: enter image description here

I tried this but with no success:

enter image description here

Is this even possible or do i have to use something else than 9 patch?


Solution

  • Your use-case is exactly what 9-patch was invented for, so it should work!

    Here are some common errors that might occur while using nine-patches:

    • Did you make your image with the draw9patch-tool ? Making it in photoshop or another photo-editing app, it is possible that the outer pixels are not completely white or black.
    • Is your filename correct ? (ending in .9.png)
    • If you put your nine-patch image in a resource-folder with a larger density then the device's density you are testing on, the image is probably scaled down and one of your black-pixels (on the left or the top) are removed.

    You can solve this by either

    1. Providing nine-patches for all densities (ldpi, mdpi, hdpi, xhdpi) (bold ones are the most common ones) <-- Preferred!

    2. Make your nine-patch for xhpdi and draw a minimum of 2 black pixels. Because when scaling down from xhdpi to mdpi, your image is scaled down with a factor of 2, so if you only draw 1 black pixel in xhdpi, it might be removed when scaling down.

    Hope this works for you.