The Nine-patch picture is a specially processed PNG image that specifies which areas of the picture can be stretched and which areas are not.
(a) defects in the normal picture being stretched
There is the following XML file, where the background image of the sub-linearlayout is set to a PNG image named Chat:
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent"5 android:orientation= "vertical" >6 7 <LinearLayout8 Android:layout_width= "Match_parent"9 Android:layout_height= "Wrap_content"Ten Android:background= "@drawable/chat" > One </LinearLayout> A - </LinearLayout>
The display results are as follows:
and Chat.png's original image is this:
Visible severe deformation, because the width of the chat.png is not enough to fill the width of the entire screen, the entire picture has been evenly stretched, this is not tolerated! So we're going to process it into a nine-patch picture.
(ii) How to make Nine-patch pictures
1, under the Tools folder of the Android SDK, there is a draw9patch.bat file, it is used to make nine-patch pictures.
2, open this software, click File->open 9-patch will chat.png loaded in, as follows:
3, you can draw a small black dot in the picture's four borders, the top border and the left border portion of the picture when the image needs to be stretched to stretch the black spot marked area, the bottom border and the right side of the frame is drawn to indicate that the content will be placed in the area, such as:
4, modify the good click File->save 9-patch, Save the picture to Chat.9.png, and then copy the chat.9.png to the drawable directory of the project, and delete the original chat.png, then look at the effect there is no tensile deformation ugly situation (note: At this point in the XML is still written: Android: background= "@drawable/chat" instead of:android:background= "@drawable/chat.9")
Android make and use Nine-patch pictures