The android program summarizes the adaptability of screen resolutions of different mobile phones

Source: Internet
Author: User

Mobile phones in various Android operating systems are a wide array of screens, and the differences in screen resolutions can be imagined. Currently, WVGA = 800x480, hvga = 480x320, and qvga = 320x240. Of course, there are also meizu M9 dvga = 960x640, and Motorola's fwvga = 854x480.

In fact, do you use a lot of padding in your layout XML file? If so, it hurts. This layout will never adapt to all cell phone screens.

The correct method should be to use the weight attribute. Set the width and height in the layout of your control to fill-parent. Do not use wrap -- content. Because the size of wrap-content is not fixed. The weight attribute solves this problem well.

When the width and height attributes of layout enclosed in the control are set to fill-parent, the inverse ratio of weight can be used. That is, if control a sets weight to 5 and control B sets weight to 7, the space occupied by a is 5/(5 + 7 ), B occupies 7/(5 + 7 ). This inverse correlation property is suitable for mobile phones at any resolution.

Of course, the font won't work. So how can we ensure that the font can be adaptive like the layout?
Ha ha, very simple, is to create a folder in your res folder, called values-320x240. 320x240 is the resolution of your mobile phone screen. It is named differently based on your mobile phone screen, for example, values-800x480. Create a dimens. xml file in the folder to define the font size. Then the system will automatically call the response folder based on the resolution of your mobile phone screen.

In addition, remember the dimens under your default values file. the corresponding font size should also be written in the XML file, because when the system cannot recognize the screen size of your mobile phone, it will automatically go to your default file

Something. If it is not written, the program will crash.

**************************************** ******************* **************************************** *

Before reading the following content, please refer to the following article in your SDK document:

In fact, Google has clearly written the adaptability to resolution, but many of us have not read it.

Conclusion:
Screen Resolution: 1024x600
Density: 1 (160)
Folder: values-mdpi-1024x600

Screen Resolution: 1024x600
Density: 1.5 (240)
Folder: The values-hdpi-683x400 is obtained from 1024/1. 5 600/1. 5 and needs to be rounded up.

Screen Resolution: 800x480
Density: 1 (160)
Folder: values-mdpi-800x480

Screen Resolution: 800x480
Density: 1.5 (240)
Folder: The values-hdpi-533x320 is obtained from 800/1. 5 480/1. 5 and needs to be rounded up.

And so on
Generally, you need to create the values, values-mdpi, and values-hdpi folders to prevent the resources from being found on some screens of unspecified sizes.

Then, use different dimens files. Do not use the displayed numbers in layout. All dimension definitions reference the content in dimens.

This ensures deep UI customization.

In addition, if split. density = false in default. Properties of the project, the folder name does not need to be separated from scale when the resolution is adapted.

Example
Screen Resolution: 800x480
Density: 1.5 (240)
Folder: values-hdpi-800x480

**************************************** ******************* **************************************** *

About dimens

Location: res \ values
Unit: pixel. The unit is the pixel of the screen;
In inches is measured in inches;
MM millimeter is measured in millimeters;
PT points 1/72 inch;
DP or dip density-indepentdent is a pixel of the 160dpi screen;
AP scale-independent pixels: a pixel that varies with the screen size;

The final conclusion is that if you don't want to seek help, you must pass the English !!!

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.