Android supports multi-screen Mechanism

Source: Internet
Author: User

Terms
1. screen size: the actual screen size.
The actual size of the android lecture screen is divided into three general sizes.

2. Aspect Ratio

3. Resolution resolution

4. Density

 

5. Density-independent pixel density-independent pixels

Description: adnroid1.6 or later sdks. A new <supports-screens> element is provided in androidmanifest. XML to support the multi-screen mechanism.
<Supports-screens
Android: largescreens = "true" whether large screen is supported
Android: normalscreens = "true": whether screen capture is supported
Android: smallscreens = "true" whether small screen is supported
Android: anydensity = "true" whether different density is supported
/>

Android provides three ways to process screen self-adaptation
I. Pre-scaled resources (search for images based on size and density)
1. If the corresponding size and density are found, use these images for no scaling hours.
2. If the corresponding size cannot be found, and the density is found, the image size is considered to be "medium", and the image is scaled to display.
3. If none of them match, use the default image for Zoom display. The default image is standard with "medium" (160) by default ).

Ii. Automatically scaled pixel sizes and coordinates (density compatibility)
1. If the app does not support Android: anydensity = "false", the system automatically scales the image size and coordinates of the image.
(Reflected in code)
2. for pre-scaled resources, this parameter does not take effect when Android: anydensity = "false.
3. Android: anydensity = "false", which only works for density compatibility, but does not work for dimension compatibility.

3. compatibility mode displayed on large screen, size (size compatible)
1. for large screens that are declared not supported in <supports-screens>, if the screen size is normal, the system displays the screen size ("normal") and density ("medium.
2. for large screens that are declared not supported by <supports-screens> and whose screen size is larger, the system also uses the size ("normal") and density ("medium) display, but a black background will appear. Not centered.

Independent density:
By default, the application supports dip units. Three dip units are used:
1. Use dip to pre-scale resources when loading resources.
2. When dip is used in layout, the system automatically scales.
3. Auto scaling of absolute pixels in applications.
(Effective only in Android: anydensity = "false"), that is, screen Adaptive Mode 2.
4. Dip is used for pixel units and SP is used for text units

Best independent screen practices:
1. Use wrap_content, fill_parent, and dip as the pixel unit in XML layout files.
2. Avoid using absolutelayout
3. In the code, do not use pixel numbers for hard encoding, but convert them to PX through dip.
Example:
You use the gesture analyzer to analyze a scroll gesture. Assume that the rolling distance is 16 PX.
1. On a 160dip screen, you can actually move 16px/160 DPI = 1/10th of an inch (or 2.5mm)
2. On a 240 dip screen, you can actually move 16px/1.7 DPI = 1/15th of an inch (or mm)
// The gesture threshold expressed in dip
Private Static final float gesture_threshold_dip = 16366f;
// Convert the dips to pixels
Final float scale = getcontext (). getresources (). getdisplaymetrics (). density;
Mgesturethreshold = (INT) (gesture_threshold_dip * scale );
4. Use density and/or size-specific resources (via folders)

About pre-scaling or auto-scaling images or 9-gram Images
1. The system must properly scale the images in the resource package.
For example, a 160x160 high-density image is displayed on a screen with a medium-density image.
2. You will not get the scaled image size in the API, and you will still get the original image size.
3. If you do not want the system to automatically scale your images, you can create a res/drawable-nodpi folder to store your images.
4. You can also use bitmapfactory. Options to automatically scale an image or a 9-gram graph (when drawing a picture ).
5. Auto-scaling images consume more CPU resources than pre-scaling images, but use less memory (RAM or Rom ?)

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.