Nine patch image not working on my device?

前端 未结 4 1027
一生所求
一生所求 2020-12-06 23:41

This is the first time i use nine-patch image on my android app. It so stupit. When I preview on eclipse layout editor, it work. But when I build the application on real dev

相关标签:
4条回答
  • 2020-12-07 00:17

    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.

    0 讨论(0)
  • 2020-12-07 00:28

    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) enter image description here

    0 讨论(0)
  • 2020-12-07 00:38

    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!

    0 讨论(0)
  • 2020-12-07 00:39

    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

    nine patch

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

    0 讨论(0)
提交回复
热议问题