Create and use an image in androidwork -.9.png format-1

Source: Internet
Author: User

When developing an application, if the interface of an application is too ugly, the first impression of the user is that this product is very junk, even if the function is very powerful. Of course, you don't have to worry about the big company's code farmers, because there are a lot of art talents to handle this aspect, but if you are a small company, or you want to develop your own applications, there is no attractive interface that won't be noticed by users. If you are fond of applications developed by yourself, it would be even better.

There are a few useless words. It has been time to clear the .9.png image and simply record it to avoid forgetting it later. Although there are a lot of online users, they are confused, upset, and do not meet their own needs.

.9.png is actually a PNG image, but it is 1 px (pixel) More border than a normal PNG image, in addition, images in this format can achieve Adaptive Background size without losing the effect. For example, after the horizontal and vertical screen switching of some controls, the controls will become distorted, or some images will also become distorted as the control background, which will be depressing. Fortunately, .9.png images provide the functions required.

Procedure

1,Make your own PNG image, which must be a PNG image. You can also decompress the APK file of other applications and use the image resources in it. The Android system can also use image resources ()

2,FindDraw9patch. batFile, open it, and drag the PNG image you want to process into it. Or file --> open 9 patch

Black line above: horizontal stretch area, must be painted, stretch is horizontal stretch, such as the right area of the second stretch is the effect of horizontal stretch

Black line on the left: vertical stretch area, which must be drawn. The stretch area is vertical. For example, the first stretch area on the right is vertical stretch.

Black line below: (optional) Horizontal content display area

Black Line on the right: optional, vertical content display area

You can try the rest.

3,Note that the black line must be continuous. If you do not feel well drawn, Shift + left mouse button to erase it and then paint it again. Click file --> Save 9-patch to save the image. The effect is shown in figure

4,Next we need to use this image in the program. Put this image in drawable. It is no different from other images. The only magic is that it can be adaptive without distortion.

For example, if we use this image to define a buttoner and add a textviewbackground image, it is also a .9.png image.

Main. xml

<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: padding = "6dp"
Android: Orientation = "vertical">

<Textview
Android: layout_gravity = "right"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: padding = "5dp"
Android: Background = "@ drawable/sms_out_normal_bg"
Android: text = "http://www.cnblogs.com/loulijun/425n -- huarang"/>

<Button
Android: Id = "@ + ID/sendmsg"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_gravity = "center"
Android: padding = "10dp"
Android: Background = "@ drawable/test"
Android: text = "send a message to Yun Er"
/>
</Linearlayout>

The running effect is as follows:

 

Article selection:

Http://www.cnblogs.com/qianxudetianxia/archive/2011/04/17/2017591.html

Http://www.learningandroid.net/blog/advance/9-patch-listview-coner/

Http://blog.csdn.net/xiaominghimi/article/details/6107837

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.