While I was working on my first Android app, I found 9-patch (aka 9.png) to be confusing and poorly documented. After a little while, I finally picked up on how it works and decided to throw together something to help others figure it out.
Basically, 9-patch uses png transparency to do an advanced form of 9-slice or scale9. The guides are straight, 1-pixel black lines drawn on the edge of your image that define the scaling and fill of your image. By naming your image file name.9.png, Android will recognize the 9.png format and use the black guides to scale and fill your bitmaps.
Here's a basic guide map:
When i use 9 patch image it gave error No resource found?
Plz give proper guideliness.
its well explained
thanx for sharing .
A good introduction to 9-patch images
Along with the multiple stretch regions, would be worthwhile to point out:
– trying to shrink the size of a 9patch (e.g. by specify height in xml that’s smaller than the image’s height) will typically result in nasty visual artefacts.
– some tools available for creating/editing.
In tutorial you said image size should by 48×48 and after creating 1 pixel black line line its size become 50×50.
1. Please tell me what should be original image size for xhdpi, hdpi, ldpi and mdpi?
2. Do I first create an image for xhdpi, hdpi, ldpi and mdpi and then separately create 9 path image?
xhdpi == 2x mdpi
xxhdpi == 3x mdpi
What is left scale & right scale?
i hav written a code to click an image and set it on an imageview.
nw how do i stretch this image?? i.e. dynamically…
was not ableam now able to to understand the 9-patch but done it bro! Hats off to youThank you !
Android won’t recognize a 9-scale without something on the left side. That’s why I did a full bar, so it stretches naturally, which in this case is not at all.
If i am using these images ‘a black border’ is coming. that is 1 px guide line as u said in ur tutorial. how to remove it.
or am I missing something, Please help!!!
thank