Working with 9-patch (Nine Patch) images in Android

2. the portion of the image where the Android’s view object can render the content ( eg : caption of a button )

Demonstrating the use of 9-patch image

Please see the images( Figure1, Figure2 and Figure3 ) given below.

Figure 1 : Normal image

Figure 2 : Patched Image

Figure 3 : Buttons with Normal Image and Patched Image

Button1 uses the image shown in Figure1 as background image

Button2 uses the patched image shown in Figure2 as background image

In the case of Button1, the whole shape of the button is changed from its original background image. Also the edges of the button is blurred.

In the case of Button2, the shape of the button remains unchanged as well as the edges are still sharp in appearance. Due to these reasons, the use of nine patch ( 9-patch) images are highly entertained.

Now let us see, how the application shown in Figure3 is developed.

For its development, Eclipse 3.7.2 is used and is tested in Android Virtual Device of API 2.3.

The patched image is created using the tool draw9patch which is shipped with Android SDK and is available in its tools directory.