Android resolution screen adaptation

Source: Internet
Author: User

In general, we may only consider qvga, hvga, WVGA, fwvga, and dvga. However, if we leave the phone blank, we may use a tablet like wsvga's 1024x576 and wxga's 1280x768.

Qvga = 320*240;
Wqvga = 320*480;
Wqvga2 = 400*240;
Wqvga3. = 432*240;
Hvga = 480*320;
VGA = 640*480;
WVGA = 800*480;
Wvga2 = 768*480;
Fwvga = 854*480;
Dvga = 960*640;
Pal = 576*520;
NTSC = 486*440;
Svga = 800*600;
Wsvga = 1024*576;
XGA = 1024*768;
Xgaplus = 1152*864;
Hd720 = 1280*720;
Wxga = 1280*768;
Wxga2 = 1280*800;
Wxga3. = 1280*854;
Sxga = 1280*1024;
Wxga4 = 1366*768;
Sxgaminus = 1280*960;
Sxgaplus = 1400*1050;
Wxgaplus = 1440*900;
Hd900 = 1600*900;
Wsxga = 1600*1024;
Wsxgaplus = 1680*1050;
Uxga = 1600*1200;
Hd1080 = 1920*1080;
Qwxga = 2048*1152;
Wuxga = 1920*1200;
Txga = 1920*1400;
Qxga = 2048*1536;
Wqhd = 2560*1440;
Wqxga = 2560*1600;
Qsxga = 2560*2048;
Qsxgaplus = 2800*2100;
Wqsxga = 3200*2048;
Quxga = 3200*2400;
Optional Hd = 3840*2160;
Wquxga = 3840*2400;
Hd4k = 4096*2304;
Hxga = 4096*3072;
Whxga = 5120*3200;
Hsxga = 5120*4096;
Whsxga = 6400*4096;
Huxga = 6400*4800;
SHV = 7680*4320;
Whuxga = 7680*4800;

 

The following code must be configured in androidmainfest:

<Supports-screens

Android: smallscreens = "true"

Android: normalscreens = "true"

Android: largescreens = "true"

Android: xlargescreens = "true"

Android: anydensity = "true"/>

If you do not have these lines of code, no matter how you adjust the controls in layout, the phone with the corresponding resolution has no effect. Note: Because different Android versions do not support xlargescreens, you can remove Android: xlargescreens = "true" directly.

 

Terms and concepts related to mobile phone resolution

Screen size: the actual physical size, diagonal measurement of the screen. For convenience, Android divides all the screen sizes into four broad sizes: small, normal, large, and extremely large.

Screen density: the number of pixels in the physical area of the screen, usually known as DPI (points per inch ). For convenience, Android divides all the actual screen density into: low, medium, high, and extremely high.

Direction: from the user's point of view, it is the screen direction, that is, the horizontal or vertical meaning.

Resolution: The total number of physical pixels on the screen. (Officially, applications should focus only on screen size and density)

Density-independent pixels: a virtual pixel unit (officially, you should use density-independent pixels to define the UI layout to express the layout size or position, by default, the system assumes that the "medium" density screen is the benchmark, and its screen density is equivalent to a DPI screen. During running, the system scales the DP unit according to the actual screen density. You can use the PX = DP * (DPI/160) method to convert the DP unit to screen pixels. On a 160dpi screen, 1dp = 1px. On a 240 DPI screen, 1 dp = 1.5px. When defining the layout, we should use the DP Unit to ensure that the user interface is properly displayed on the screen of different density)

About the supported screen range

Four broad dimensions are officially defined: small, normal, large, and larger. Four types of density: low, medium, high, and extremely high. Both the general size and density can span a series of dimensions and density (the official upload does not have sufficient permissions for one week )

Density independence

The official saying is that it is very important to ensure the independence of density. Without it, system controls in your application may display exceptions on screens with the same physical size and different density.

There are two independent Android system help density methods:

1. Use the DP unit.

2. Bitmap resource scaling can lead to blurred bitmaps of pixels. bitmaps of different resolutions can be provided based on the current screen density. Official tips: if a set of images are provided, at least a higher resolution and high density bitmap is provided, rather than a medium density design bitmap.

How to support multiple screens

The official statement ensures that the system has done a lot of work to adapt to multiple screens, but we also need to do some work to better handle different screen configurations:

1. display a list of screen sizes that declare that your application supports.

<Span style = "font-family: kaiti_gb2312; font-size: 16px;">
Android: resizeable = ["true" | "false"]
Android: smallscreens = ["true" | "false"]
Android: normalscreens = ["true" | "false"]
Android: largescreens = ["true" | "false"]
Android: xlargescreens = ["true" | "false"]
Android: anydensity = ["true" | "false"]/> </span>

2. provide different la s based on different screen sizes

By default, Android automatically adjusts the layout of the application. However, in most cases, different layout resources are added based on the general size, small size, normal size, and larger size. For example, to support a screen with a size of large, you need to create a folder named Layout-large/In the res directory and provide layout. Of course, you can also create the layout-port and layout-land directories under the res directory, which place two layout files, vertical screen and horizontal screen, respectively, to automatically switch the portrait screen.

3. provide different screen density and different bitmap drawables

By default, the system will automatically adjust and scale the bitmap, but it is inevitable to stretch the bitmap. To ensure that your bitmap is the best-looking, according to the broad senseDensity,Low, medium, high, and extra high add different bitmap resources. For example, to provide a suitable picture for a screen with a low density, you need to create a folder named drawable-ldpi /. Try to use images in the format of. The image size is determined as follows: low: Medium: high: extra high ratio is 3: 4: 6: 8. For example, for a medium screen, if the pixel size of your image is 48 × 48, the low-density screen size should be 36 × 36, and the high) is 72 × 72, extra high is 96 × 96.

How can the system dynamically find alternative resources?

1. The system dynamically uses programs to provide specific resources based on the current screen size and density.

2. If no matching resource exists, the system scales the resource with the default resource to match the resource on the current screen. The "default" resource is the resource with no tag configuration qualifier.

(This is just a simple statement. For details, refer to the next chapter on finding alternative resources)

Directory for system resource configuration(I only list some general items. Some resource configuration directories are available in the default project)

The Android system supports multiple configuration resource files. We can append a new resource directory to your android project. Naming rules: Resource Name-delimiter

 

 

Note: If the landscape or portrait screen is not specified, both the layout and the bitmap above are applicable to the landscape and landscape screens. If you want to specify a horizontal screen, such as drawable-land-hdpi portrait screen drawable-Port-hdpi, the key is drawable-xlarge and layout-xlarge, the requirements for API level are above 9, which means that the tablet or mobile phone of your Android system does not match Layout-xlarge at all. Because the API level is 8. Drawable-tvadpi requires more than 13 API levels.

In fact, the preceding Layout-large directory is actually a range. When the system determines the directory that the program should match based on the size and density of the current screen. You can also individually customize some layout-l024x600 that does not comply with Google standards (the middle of the match is an English letter X), of which 1024 and 600 are in DP. You can determine the file that your device needs to define based on the resolution and density of your device.

However, we recommend that you use dimensions to indicate resource Layout-large. The resolution Layout-1024*600 is not recommended.

We recommend that you read more documents. Official Instructions:

Xlarge screens are at least 960dp x 720dp

Large screens are at least 640dp x 480dp

Normal screens are at least 470dp x 320dp

Small screens are at least between DP x 320dp

The above defines a range for resource adaptation in a broad-sized layout. you can know that the system will match the layout of the file based on your device.

If there is a popular mediapad sold by Huawei, we know that the resolution is 1280*800, and the density is 7 inches.

The density is 215.69 according to the check and resolution. Then, according to dp = px/(DPI/160), a range of 593.471 can be obtained. Therefore, the device system will match the resource layout file Layout-large.

 

  Screen type Resolution Density Dimensions
Drawable-hdpi WVGA 480*800 240 Large
Drawable-ldpi Qvga 240*320 120 Small
Drawable-mdpi Hvga 320*480 160 Medium

 

1. Basic Concepts

Screen size: the actual screen size, measured by the diagonal length of the screen (such as 3.4, 3.8 ). Android divides the screen into the following four types: small, normal, large, and extra large.
How to judge?

Screen density-the number of pixels in an actual screen area, measured by DPI (the number of dots per inch ). Compared with medium and high screen density devices, the L density of a fixed screen area has less pixels than that of A Low screen. Android classifies screen density into four types: low, medium, high, and extra high.

How can we determine whether it is ldpi, mdpi, or hdpi?

Orientation-screen orientation is divided into landscape and portrait ).

Resolution-the total number of workers on the screen. When you adapt a screen, you generally do not focus on its resolution, but on its screen size and density.

Density-independent pixels (density-independent pixel, DP or DIP)-to ensure that your UI is suitable for different screen density, we recommend that you use DP to define the program UI.
Its calculation method is: Px = DP * (DPI/160)

SP (scale-independent pixel)

How to distinguish a screen from ldpi, mdpi, and hdpi is shown in

 

Calculate screen Density

 

2. How to Adapt to multiple screens

A. Define the screen types supported by your program in manifest. The Code is as follows:
<Supports-screens Android: resizeable = ["true" | "false"]
Android: smallscreens = ["true" | "false"] // whether small screens are supported
Android: normalscreens = ["true" | "false"] // whether the screen is supported
Android: largescreens = ["true" | "false"] // whether the screen is supported
Android: xlargescreens = ["true" | "false"] // whether ultra-large screen is supported
Android: anydensity = ["true" | "false"] // whether screens of different density are supported
Android: requiressmallestwidthdp = "integer"
Android: compatiblewidthlimitdp = "integer"
Android: largestwidthlimitdp = "integer"/>

B. Provide different layout for screens of different sizes.

For example, to support a screen with a size of large, you need to create a folder named Layout-large/In the res directory and provide layout. Of course, you can also create the layout-port and layout-land directories under the res directory, which place two layout files, vertical screen and horizontal screen, respectively, to automatically switch the portrait screen.

C. Provide different images for screens of different density.
Try to use images in the format of. To provide suitable images for low-density screens, you need to create a folder named drawable-ldpi/and add images of the appropriate size. Correspondingly, medium corresponds to drawable-mdpi/, high corresponds to drawable-hdpi/, and extra high corresponds to drawable-xhdpi /.
Determine the image size: low: Medium: high: extra high ratio is 3: 4: 6: 8. For example, for a medium screen, if the pixel size of your image is 48 × 48, the low-density screen size should be 36 × 36, and the high) is 72 × 72, extra high is 96 × 96.

 

Ratio of images corresponding to screens of different density

 

3. Four golden principles for multi-screen adaptation
A. wrap_content, fill_parent, and DP should be used to set the control size in the layout file.

Specifically, wrap_content, fill_parent or DP are better than pix when you set the value of the view attributes Android: layout_width and Android: layout_height. Correspondingly, SP should be used to define the text size in order to make the text size better adapt to the screen.

B. Do not show specific pixel values in the program code.

To make the code simple, Android uses the PIX to represent the widget size in units, but this is based on the current screen. To adapt to multiple screens, Android recommends that developers do not use specific pixels to represent the widget size.

C. Do not use absolutelayout (android1.5 has been deprecated ). Correspondingly, relativelayout should be used.

D. provide images of the appropriate size for different screens. See section 2nd above.

4. Notes
The preceding settings apply to versions earlier than Android. (I am currently developing on android2.2. I will add this part later)

5. How to test whether your program supports multi-screen adaptation
Generally, AVD manager is used to create multiple Simulators of different sizes, such

 

Related Article

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.