Search code examples
androidandroid-studiopngnine-patchaapt

9-patch image error


I have a project that builds and works, but my images (png) doesn't adapt to the phone.

Actually, I have 10 images, and I put them in all drawable folder : -drawable-hdpi have 10 images -drawable-mdpi have the 10 SAMES images (same name, same size, same resolution) - ... same for xhdpi, xxhdpi, xxxhdpi

1) I tried to use Simple Nine-patch Generator, from AndroidAssetStudio this way : http://romannurik.github.io/AndroidAssetStudio/nine-patches.html

  • I took my first image, uploaded it onto the generator, downloaded the zip, and extracted each file in the proper folder.
  • Then I run my app and I got this error :

    ERROR: 9-patch image ../../IMAGE_1.png malformed. Frame pixels must be either solid or transparent (not intermediate alphas)

2) Then I tried to go back to the original .png, and used /Android/Sdktools/draw9patch, and put the .9.png generated in the right folder.

And I got this error:

ERROR: 9-patch image ../../IMAGE_1.9.png malformed.
AAPT:        No marked region found along edge.
AAPT:        Found along top edge.

Here's one of my original images:

p11_titre.png

and here's the generated version :

enter image description here


Solution

  • OK, this is your 9 patch.
    There's a bad pixel on the bottom marker.

    enter image description here

    And this is how it will stretch, due to the markers you set.

    enter image description here


    This is my fixed version (note the top markers: 2 single pixels)

    enter image description here

    And this is how it nicely stretches (width only, because of the curved edges - You can add a transparent line on top and bottom to make it leave some "space", the left side markers would then have to be made 2 single pixels, one per each transparent line).

    enter image description here