In traditional UI development, if the background size is different, you generally need to create an image for each size, which is particularly evident in the button. Of course, we can also make a small horizontal duplicate or vertical painting. In Android, when there is an nine patch image (ending with 9.png) to solve the difference in the background size, only one background image is used.
Use the built-in tools/draw9patch. BAT to open a PNG image. We can draw a black line with pixel width in the outermost space of the PNG image. On the left is the editing area. In the picture on the left, the height of the black line on the left determines the extended area during vertical pull. That is, when vertical stretch is performed, only the image in this area is stretched. Similarly, the black line length on the image determines the extended area when the horizontal pull is performed. The area on the right is vertical, horizontal, and vertical respectively. This tool provides the WYSIWYG nine patch PNG editing method.
Save the edited PNG as 9.png to the res/drawabledirectory of the project directory. If your 9.png file does not contain a black line, eclipse will report an error.
As follows. We can also understand why nine patch is called. It is equivalent to dividing a PNG image into nine parts, including four corners, four sides, and an intermediate area, the four corners are not raised, so the rounded corners can be kept in the state, while the two horizontal and vertical sides are only horizontally and vertically stretched, therefore, the side will not be grayed out, and only the area specified by the black line is stretched in the middle. The result is that the image is not displayed.
Note: To draw two black lines in the horizontal and vertical directions of the image, you only need to select the position and press and hold the left mouse button to slide.
In, 1, 2, 3, 4 areas will not stretch with the image, only other areas will stretch.
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/lijiecong/archive/2009/11/05/4774327.aspx