Nine patch image not working on my device?

冷暖自知 提交于 2019-11-28 01:44:01

Remove two dots from bottom and right side because these side decides in how much space your content should be displayed.

and here is how the nine patches work in android

And Follow this tutorial when you create a nine patch image.

I solved it by my self but I don't understand why it works.

In nine-patch, I draw 2 line at the top and the left of image (see 2 black lines at the picture)

I tested it more deeply, and it seems that there are inconsistencies between the draw9patch tool, Graphical editor in Eclipse and the device. Nine-patches, that seem to work in the first two, do not work on the device - they silently fall back to BitmapDrawable, without reporting an error. Reproduces on my 2.3.5 device, as well as in 4.1 emulator. See this android bug: http://code.google.com/p/android/issues/detail?id=38941

Workaround is to draw single row of pixels, not just dots.

TIP: your image should be as small as possible. If you put two dots to the left or top region, it means, that you have two stretched areas and the area between them is kept unstretched. You can cut out the area from the first dot (excluded) to the second dot (included) and have only one dot, with a smaller image and the same result.

TacB0sS

The image I'm using has a shadow, and brilliantly I assumed that it ends before it reaches the last pixel of the image... and so didn't bother to enlarge the image by a pixel... (I know the 9 patch tool is doing this for me but I was in the middle of editing the image so I just added it there)

So the problem is The preview can handle pixels with alpha, the 9-patch tool can handle it as well, but the device cannot!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!