Search code examples
androidnine-patch

Why does my 9patch cast shadows / artifacts on some devices but not others?


Depending on the device, my 9patch is acting differently. Ideally, it looks like this:

good matrix

Which is the result I get on a Nexus 4. However, on a Nexus 7 I'm instead getting this:

bad matrix

It's stretching properly, but there's a shadow over what should be transparent. draw9patch.bat says there are no bad patches, and stretches correctly. The two devices are different resolutions (xhdpi and hdpi), but I made sure to include the same 9patch in both folders (drawable-xhdpi and drawable-hdpi).

matrix 9patch


Solution

  • I used to have problems with 9patch when setting just un pixel in any of the four sides.

    I see that in your 9patch you are only using one pixel to draw some of the lines that define the stretchable patches and content area. Try using more than one pixel in top, left and right sides of your 9patch.