Teach you how to do Bluetooth chat application (vi)-Interface optimization

Source: Internet
Author: User

The 6th section applies the beautification and the consummation

Now, we can also add multi-language support for the chat application and about the interface, the color and size used to define the resource file, so that the Bluetooth chat application of the beans is relatively complete.

These two parts in the previous " Calculator " chapter, has already introduced, everybody will do it yourself.

In this section, we will focus on how the background image of the chat text is made.

The principle of 6.1 9Patch picture

Take a look at the images that you need to use frequently in your Android system to discover:

    1. A lot of places to use transparent effects at the corner;
    2. Many pictures are different places only near the edge of the place, the interior area is almost the same;

For this reason, the Android system has developed 9patch images based on PNG images, allowing images to occupy less space. Its format is xxx.9.png . The background of the chat text we will use 9patch image, it is placed in the res\drawable directory. 9patch picture and ordinary PNG image, just in four weeks more than 1 pixels wide black line, these four black lines cross each other, just to divide the picture into 9 Gongge, so called 9patch.

6.1.1 left line and upper line

The area covered by the left line (dark yellow, blue, pink) can be stretched up and down, the area covered by the line (green, blue, black) can be stretched left and right, and the intersection of the line and the line can be stretched up or down (in the blue area);

When a 9patch image needs to be scaled according to the size of the control, the area on the Four Corners (brown, cyan, yellow, purple) is not scaled, and only the area that can be stretched is scaled to fill the entire control.

6.1.2 Right line and bottom line,

The area of the right line and the intersection of the downline represents the content area. For example, the text area of a button.
The display area is the area that can be used to display text content after being stretched.

It is important to note that the left and top lines must be there, and the right line and the Downline bar can not. When the right and bottom lines are not there, the intersection of the left and upper lines is not only an extension of the area, it also indicates that the area is a text display area.

6.2 9Patch Image Production

The Android SDK provides a tool for making 9Patch images, which is placed in sdk目录\tools\ this position, named draw9patch . This tool allows you to add a black line to a PNG image, such as four edges, and turn it into a real 9.png picture.

But here, we will use the online build tool provided by Android Asset Studio. Because it can generate images that correspond to multiple pixel densities at once.

    1. Open Android Asset Studio selectionSimple nine-patch generator

    2. Select the picture you want to work with,

    3. Set the area allowed to scale,

    4. Set the area you can use to display text

    5. Preview effects, download pictures,

6.3 Use of 9Patch images

After the picture is downloaded, the compressed package is decompressed, and the image corresponding to the density of different pixels is automatically generated. Put these pictures in the Project res catalog,

/*******************************************************************/
* Copyright Notice
* This tutorial is only published in CSDN and the green Bean Network, other websites appear this tutorial is infringing.
/*******************************************************************/

7th Quarter PostScript

Now, we can also add multi-language support for the chat application and about the interface, the color and size used to define the resource file, so that the Bluetooth chat application of the beans is relatively complete.

These two parts in the previous " Calculator " chapter, has already introduced, everybody will do it yourself.

Through this chapter of practice, we are exposed to the initial network programming, multi-threaded cooperation. Because of the use of Bluetooth technology, but also for the future of Bluetooth-related intelligent hardware development laid the foundation.

But, as we mentioned in the opening, this application leaves a lot of regret,

    1. Does not let the Bluetooth connection as Service in the background to run, received the message can notify the user with the notification;
    2. You cannot record the content of the chat when the app was last launched;
    3. No ability to view each other's personal information;

In the application process, you will also find a lot of things such as the above feel worth adding features and improvements. So this version of the Bluetooth chat app is just a rough version, we should be in the back, add on those practical features.

Teach you how to do Bluetooth chat application (vi)-Interface optimization

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.