Android make and use Nine-patch pictures

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.