Search code examples
androidandroid-xmlseekbarnine-patch

org.xmlpull.v1.XmlPullParserException: Binary XML file line #5: <nine-patch> requires a valid 9-patch source image


I want to create a custom seek-bar. Along with other resources I have followed this two examples:

http://developer-dot-android.blogspot.ro/2012/03/custom-seekbar-tutorial.html

http://www.mokasocial.com/2011/02/create-a-custom-styled-ui-slider-seekbar-in-android/

http://code.google.com/p/android-apktool/wiki/9PatchImages

All what I have tried crash at this line:

   ........
  <nine-patch
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:dither="true"
    android:src="@drawable/whitepatch">
  </nine-patch>

with:

Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #5: <nine-patch> requires a valid 9-patch source image
04-16 15:46:45.242: E/AndroidRuntime(20508):    at android.graphics.drawable.NinePatchDrawable.inflate(NinePatchDrawable.java:320)
04-16 15:46:45.242: E/AndroidRuntime(20508):    at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:881)
04-16 15:46:45.242: E/AndroidRuntime(20508):    at android.graphics.drawable.LayerDrawable.inflate(LayerDrawable.java:165)
.....

I have tried to generate my own 9-patch images using draw9patch.bat tools from sdk as described here. (without any other workaround because I don't know how, just import the .png and then save it as .9.png).

I have try to copy/paste the whitepatch.9.png used in the first tutorial, into my project. Same result. I really don't know what to do with this. Please help me!

enter image description here


Solution

  • Nine Patch Image is an PNG image with the extension 9.png. The Nine Patch image contains the meta information about the Scalable area (Top and Left) and Content area (Right and Bottom). You must mention the mandatory scalable area by marking around the top and left with 1 pixel(black color) excluding the corners which is distorted when scaled otherwise Android won't recognize it as a Nine Patch Image.

    The below links will be more helpful

    http://radleymarx.com/blog/simple-guide-to-9-patch/

    http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch

    https://github.com/chrislondon/9-Patch-Image-for-Websites/wiki/What-Are-9-Patch-Images

    http://www.androiddom.com/2011/05/android-9-patch-image-tutorial.html