022_02android's nine Patch pictures

Source: Internet
Author: User

Ninepatch is a useful PNG image format that can be scaled with text size in a specific area. As follows:

As you can see, the middle area of the background image is scaled as the text is resized. The background image is a ninepatch picture. Ninepatch pictures can be made using Android's own Draw9patch tool, which is in the tools directory of the SDK installation path.

The source code is as follows:

1  PackageCom.example.day22_02ninepatchdemo;2 3 Importandroid.app.Activity;4 ImportAndroid.os.Bundle;5 6  Public classMainactivityextendsActivity {7 8 @Override9     protected voidonCreate (Bundle savedinstancestate) {Ten         Super. OnCreate (savedinstancestate); One Setcontentview (r.layout.activity_main); A     } -}

1 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent"5 Android:paddingbottom= "@dimen/activity_vertical_margin"6 Android:paddingleft= "@dimen/activity_horizontal_margin"7 Android:paddingright= "@dimen/activity_horizontal_margin"8 Android:paddingtop= "@dimen/activity_vertical_margin"9 Tools:context= "Com.example.day22_02ninepatchdemo." Mainactivity "Ten android:orientation= "vertical" > One  A     <TextView -         Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" the Android:text= " Hello hello hello you hello hello hello hello you hello hello hi hello hello hi hello hello hi hello hi you you hi  - Android:background= "@drawable/chatfrom_bg"/> -         -        <TextView +         Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" + Android:text= "Hello, hello, hello, Hi, Hi, hello. Hello, hello, hello, hello. Hi, hello, how are you? Hello, hello, hello, hi, how are you? Hello Hello hi hello you hello  A Android:background= "@drawable/mymsgbg2"/> at  - </LinearLayout>

: The first is an unprocessed background image, the second is a processed background image.

You can see that two pictures open with Windows Photo Viewer is not the same, and the suffix is not the same, the former is Xxx.png, the latter is xxx.9.png.

022_02android's 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.