Android miscellaneous-about Android nodpi, xhdpi, hdpi, mdpi, ldpi

Source: Internet
Author: User

About Android nodpi, xhdpi, hdpi, mdpi, and ldpi

First, there are several basic concepts:
1. Screen Size
That is, the actual size of the display screen is measured based on the diagonal line of the screen.
For the sake of simplicity, Android divides all the screen sizes into four types: small, normal, large, and super large (corresponding to small, normal, large, and extra large ).
Applications can provide different custom screen la s for these four dimensions-the platform will select the corresponding layout for rendering based on the actual screen size, which is transparent to the program side.

2. screen aspect ratio Aspect Ratio
The aspect ratio is the ratio of the physical width to the physical height of the screen. Applications can use limited resources to provide screen layout resources for the specified aspect ratio.
3. Screen Resolution resolution
The total number of physical pixels displayed on the screen. Note that although the resolution is usually expressed in width x height, the resolution does not mean the specific aspect ratio of the screen.
In the andorid system, the application does not directly use the resolution.

4. Density
Specify the number of pixels that can be displayed within the physical width and height range based on the pixel resolution.
In the same wide and high area, the low-density display displays less pixels, while the high-density display displays more pixels.
Screen density is very important, because when other conditions remain unchanged, a total of wide and high Fixed UI components (such as a button) appear very large on the low-density display, on a high-density display screen, it looks small.
For simplicity, Android divides all screen resolutions into four sizes: small, common, large, and ultra-large (corresponding to small, normal, large, and extra large ).
Applications can provide different resources for these four dimensions-the platform transparently scales the resources to adapt to the specified screen resolution.

5. Device Independent pixel density-independent pixel (DP)
Applications can be used to define virtual pixel units of the UI component and describe the layout size and position in a density-independent manner.
A device independent pixel is equivalent to a physical pixel on a 160 DPI screen.
When the program is running, the system transparently processes independent pixel units of any devices that need to be scaled according to the actual density of the screen. The conversion of independent pixels of devices into actual pixels of the screen is very simple: pixels = DPS * (density/160 ).
For example, on a 240 DPI screen, an independent device pixel equals 1.5 physical pixels. to ensure that the UI components can be properly displayed on different screens, we strongly recommend that you use device independent pixel units to define your application UI.

Differences between drawable-hdpi, drawable-mdpi, and drawable-ldpi:
(1) The drawable-hdpi contains high-resolution images, such as WVGA (480x800) and fwvga (480X854)
(2) drawable-mdpi stores medium-resolution images, such as hvga (320x480)
(3) drawable-ldpi stores low-resolution images, such as qvga (240x320)
The system will find the corresponding images in these folders according to the machine resolution.

Four types of screen sizes: small, normal, large, and xlarge
Four density classifications: ldpi (low), mdpi (medium), hdpi (high), and xhdpi (extra high)
It should be noted that xhdpi is added from Android 2.2 (API Level 8.
Xlarge is a category added from Android 2.3 (API level 9.
DPI is the abbreviation of "dot Per Inch". The number of dots per inch.

Normal screen: ldpi is 120, mdpi is 160, hdpi is 240, and xhdpi is 320.

Reference: http://developer.android.com/images/screens_support/screens-ranges.png

Two methods to obtain screen resolution information:

Displaymetrics metrics = new displaymetrics ();
Display display = activity. getwindowmanager (). getdefadisplay display ();
Display. getmetrics (metrics );
// The pixel value obtained here is the device independent pixel DP

// Displaymetrics metrics = activity. getresources (). getdisplaymetrics (); The obtained parameter information is incorrect. Do not use this method.
Android. content. res. Resources. getsystem (). getdisplaymetrics () cannot be used (). The obtained width and height are empty.
If you need to customize resource files for Android pad, the directory under the res directory may be:
Drawable
Drawable-ldpi
Drawable-mdpi
Drawable-hdpi
Drawable-xhdpi
Drawable-nodpi
Drawable-nodpi-1024 × 600
Drawable-nodpi-1280 × 800
Drawable-nodpi-800 × 480
Values
Values-ldpi
Values-mdpi
Values-hdpi
Values-xhdpi
Values-nodpi
Values-nodpi-1024 × 600
Values-nodpi-1280 × 800
Values-nodpi-800 × 480

Refer:

Http://developer.android.com/guide/practices/screens_support.html

From: http://618119.com/archives/2011/01/12/205.html

Common measurement units on Android:
Px (pixel): the point on the screen, absolute length, related to hardware.
In (INCHES): the unit of length.
Mm (mm): the unit of length.
Pt (lbs): 1/72 inch, point.
DP (density-independent pixels): An abstract unit based on screen density. 1dp = 1px on a display at 160 o'clock per inch.
Dip: density-independent pixel, which is the same as DP.
SP: Based on DP, it has nothing to do with the proportion. I personally think it is a vector graphics unit.

Reasons for the introduction of DP/dip:
In the past, programmers often designed computer user interfaces in pixels. For example, define a form field with a width of 300 pixels. the spacing between columns is 5 pixels, And the Icon size is 16 × 16 pixels. The problem with this processing is that if you run the program on a new display with a dot (DPI) higher per inch, the user interface will look small. In some cases, the user interface may be small to difficult to see the content. The measurement units irrelevant to resolution can solve this problem.

How to calculate the density (see the original post: http://www.devdiv.com/thread-28610-1-1.html );
1. The standard is 240*320 painted on 1.5*2 square inch. For example, each square inch has 240*320/(1.5*2) = 25600 points, that is, the pixel of a square inch is 25600, so DPI is the square root of 160; if your DPI is 120, the density is 0.75.
2. density is not only related to width, but also to height. Therefore, whether width is 1.8 or 1.3, its density may be 1. For example, width is 1.8, as long as its height is 3/1. if pixel is 240*320, its density is still 1. If width is 1.3, as long as its height is 3/1. if the pixel is 240*320, the density is also 1.
3.320*480/(1.5*2) Get the point in the unit square inch as 51200, so the unit square inch is 240*320 draw twice the screen in 1.5*2. But this is square inch. We need to square it when calculating the density. So it should be two square meters. It is 1.414 square meters. The approximate density is 1.5.

How to achieve density-independent:
If the screen density is 160, DP and SP are the same as PX. 1dp = 1sp = 1px, but if PX is used as the unit, if the screen size remains unchanged (assuming it is still 3.2), the screen density is changed to 320. The original textview width is set to 320 PX, And the 3.2-inch screen with a density of 160 is half shorter than the 3.2-inch screen with a density. But if it is set to 160dp or 160sp. The system automatically sets the width property value to 320px. That is, 160*320/160. Among them, 320/160 can be called the density proportion factor. That is to say, if DP and SP are used, the system will automatically convert according to the screen density change. The formula summarized in the official document is pixels = DPS * (density/160 ).

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.