Android calculates the resolution/pixel/density/Screen size/dpi value for pad or phone _android

Source: Internet
Author: User
Tags comparison table pow

Basic knowledge of mobile resolution (DPI,DIP calculation)

1. Terminology and concepts

Terms

Description

Note

Screen size (on-screen dimensions)

Refers to the actual physical size of the phone, such as 2.8-inch, 3.2-inch, 3.5-inch, 3.7-inch

Motorola Milestone mobile phone is 3.7 inches

Aspect Ratio (Wide-high ratio)

Refers to the actual physical dimensions of the wide-high ratio, divided into long and nolong

Milestone is 16:9 and belongs to long.

Resolution (resolution)

As with the computer resolution concept, refers to the mobile phone screen vertical and horizontal pixel number

Milestone is 854*480.

DPI (dot per inch)

Pixels per inch, such as 120dpi,160dpi, assume that QVGA (320*240) Resolution of the screen physical size is (2 inches * 1.5 inches), dpi=160

Can reflect the sharpness of the screen, which is used to scale the UI

Density (density)

Pixel concentration in the screen, Resolution/screen size can reflect cell phone density,

Density-independent Pixel (DIP)

Refers to the logical density unit of calculation, dip and specific pixel value of the corresponding formula is dip/pixel=dpi value/160, that is, PX = DP * (dpi/160)

2. DPI value calculation

For example: Compute WVGA (800*480) resolution, 3.7-inch density dpi, as shown in Figure 1

Figure 1

Diagonal pixel represents the pixel value (=) of the diagonal, dpi=933/3.7=252

3. The classification of mobile phone screen

3.1 According to the mobile screen density (DPI) or screen size is divided into the following 3 categories, as shown in Figure 2

Figure 2

3.2 Mobile phone screen classification and pixel density of the corresponding relationship as shown in table 1:

 

Low Density ( ldpi

Medium density (160), mdpi

High density (24 0), hdpi

Small screens

QVGA (240x320)  

 

Normal screen

WQVGA400 (240x400) WQVGA432 (240x432)

HVGA (320x480)

WVGA800 (480x800) WVGA854 (480x854)

Large screen

 

wvga800* (480x80 0) wvga854* (480x854)

 

Table 1

3.3 Mobile phone size distribution (http://developer.android.com/resources/dashboard/screens.html), as shown in Figure 3, is currently mainly based on the resolution of 800*480 and 854* 480 of mobile phone users are mostly


Figure 3

From the above screen size distribution, in fact, the mobile phone only consider 3-4 5 inches between the density of 1 and 1.5 of the cell phone

4 UI Design

From a development perspective, the application will provide 3 sets of UI layout files based on the 3-class Android phone screen, but the corresponding interface icon also needs to provide 3 sets, as shown in table 2

Icon Type

Standard Asset sizes (in Pixels) for generalized screen densities

Low density screen (ldpi)

Medium density screen (MDPI)

High density screen (hdpi)

Launcher

(x) px

X (px)

X-px

Menu

(x) px

X (px)

X-px

Status Bar

x px

x px

X (px)

Tab

x px

x px

X (px)

Dialog

x px

x px

X (px)

List View

x px

x px

X (px)

Table 2

5 How to achieve adaptive screen size?

1) Interface layout aspect

You need to prepare 5 sets of layouts based on the size of the physical size, layout (put some generic layout XML files, such as the top and bottom layouts in the interface, not with the size of the screen, similar to the title bar of the WinDOS window), Layout-small ( Screen size less than 3 inch layout), Layout-normal (screen size is less than 4.5 inches), layout-large (4 inches-7 inches), Layout-xlarge (7-10 inches)

2) Picture resource aspect

5 sets of picture resources need to be prepared according to the DPI value, drawable,drawalbe-ldpi,drawable-mdpi,drawable-hdpi,drawable-xhdpi

Android has an automatic matching mechanism to choose the corresponding layout and picture resources

Cell phone resolution pixel density and screen size are the words we often hear, the relationship between them is as follows :

Resolution is the number of container points on the screen, each of which is used to hold a pixel.

Pixel strictly refers to the picture, the more pixels on the picture, the more clear the picture, of course, will be larger.

The phone can have the same resolution, but the screen size can be different, for example, 3.7-inch screen can be 320*480 resolution, 5.1-inch screen can also be 320*480 resolution, then these 2 screens in the display what is the difference?

For example: If a cell phone screen width is 5cm,b phone width is 10Cm, width resolution is 320, then display the same picture, B phone picture will be significantly larger, and no a phone on the clear. Why, this is our common density (DPI) concept, that is, how many dots per inch. itself a line of 5CM has 320 dots, DPI is about 150, now is a row 10CM has 320 points, the density is about 75. Density is greatly reduced, so B mobile phone display of the picture will become larger, not clear. Just as we use the Android screen monitor to display the phone on a computer, it always feels a bit large on the computer because the resolution density of your computer is not as high as the resolution density of your cell phone, you can turn the computer's resolution up a bit to make the computer screen density and cell density consistent.

Conversion method:

72 pixel/inch = 28.346 pixel/cm

300 pixel/inch = 118.11 pixel/cm

1 cm = 0.3937 inches

1 inches = 2.54 cm

Pixel can not be directly converted into inches, centimeters, to be in the DPI to convert!

in a common 1024-pixel comparison :

1024 pixel = 3.413 inch = 8.67 cm (300 pixel/inch dpi ≈0.003333 pixels), so the centimeter size of 1024 pixels is: 1024*0.003333*2.54

1024 pixel = 14.222 inch = 36.12 cm (72 pixel/inch dpi ≈0.013889 pixels), so the centimeter size of 1024 pixels is: 1024*0.013889*2.54

To raise the resolution, we need to understand two concepts, image resolution and output resolution.

Image resolution is the number of pixels per inch, in PPI, the resolution of the image is often represented in each direction of the total amount of pixels, such as 640x480 pixels, 1280x960 pixels. The image output quality is determined by the output resolution of the image, which describes the number of dots per inch (dpi) that can be produced by the device's output image, in dpi, but not always equal.

DPI (dot per inch) output resolution

The printer resolution, also known as the output resolution, refers to the maximum number of points per inch that can be printed horizontally and vertically in two directions at the time of printout, usually expressed as "dots per inch", which is the DPI (dot inch). The highest resolution is the maximum resolution that the printer can print, that is, the limit resolution of the printed output. Usually said printer resolution generally refers to the maximum resolution of the printer, the current general laser printer resolution in 600x600dpi above.

The DPI is the abbreviation for "dot per inch". As the name suggests, it refers to the number of points in the length of each inch. Typically, we use the DPI as the resolution unit for Scanners and printers, and higher values indicate higher resolution. At present, the market for the sale of scanners in the optical resolution of the main 600x1200 dpi and 1200x2400 dpi two kinds. The optical resolution of the scanner is composed of two digits because of the difference between the transverse resolution and the longitudinal resolution. A smaller number is usually a longitudinal resolution, that is, we generally distinguish between the values used for scanner resolution. In other words, the 600x1200 dpi scanner, we are usually referred to as the DPI.

The resolution of the computer monitor is about 72dpi, this value is calculated in this way: to a 15-inch computer monitor For example, the visual area of the horizontal length of about 11.2 inches, if the display mode is 800x600, then the resolution is 800/11.2=71.4. If the 17-inch computer monitor, in 1024x768 display mode, the resolution becomes 1024/12.8=80.

Pixel (Pixel)

For computer screen devices, pixel (Pixel) or PX is a basic unit, is a point. All other units are in a fixed proportional conversion relationship with the pixel. All length units are based on the display of the screen, the unified first conversion into the number of pixels, and then display. Therefore, there is no essential difference between the relative length and the absolute length of the computer's screen. Any unit is actually a pixel, the difference is only a different proportion.

If you extend the discussion to other output devices, such as printers, the basic unit of length may not be pixels, but other units consistent with the unit of measure in your life.

The CSS absolute length units are for output devices (outputs device). Take PT, this is a text typesetting tool (Word,adobe, etc.) very common font units, whether your display resolution is 1024*768, or 800*600, the same document printed on paper results are the same.

Which length of the page to write a better unit, is PX or PT?

I personally prefer PX, because PX can accurately represent the position and size of the elements in the screen, the page is mainly for screen display, not for printing and other needs.

CSS relative length units (relative length unit)

The relative two words in the relative length unit of the CSS indicate that the unit of length varies with its reference value and is not fixed. The following is a list of CSS relative length units:

css Relative length units

Description

The font height of the EM element the height of the element s font

The height of the ex letter X "X"

px Pixel pixels

%% Percentage

CSS Absolute length units (absolute length unit)

The absolute length unit is a fixed value. For example, we often have mm, is the meaning of MM. The following is a list of CSS absolute length units:

CSS Absolute length unit

Description

in inch inches (1 inches = 2.54 cm)

CM cm centimeters

mm mm millimeters

PT Point points (1 point = 1/72 inch)

PC Pickup Picas (1 pickup = 12 point)

Pixels are relative to the screen resolution of the Monitor. For example, Windows users typically use a resolution of 96 pixels per inch. The user of the MAC uses a resolution that is typically 72 pixels per inch. So in Windows CSS, the DPI is 96 pixels per inch.

Additional tables are attached:

Common photo size, pixel and print size comparison table (practical)

Inches

Photo Specifications

Cm

Pixel

Digital camera Type

Print size

Resolution: 300DPI

1 inch

2.5x3.5cm

413x295

/

/

Big Head photo of ID card

3.3x2.2

390x260

/

/

2

3.5x5.3cm

626x413

/

/

Small 2 inch (Passport)

4.8x3.3cm

567x390

/

/

5 inch

12.7x8.9

1200x840 above

1 million pixels

/

6 inch

15.2x10.2

1440x960 above

1.3 million pixels

/

7 inch 7x5

17.8x12.7

1680x1200 above

2 million pixels

12.7x17.7

8 inch 8x6

20.3x15.2

1920x1440 above

3 million pixels

15.2x20.3

10 inch 10x8

25.4x20.3

2400x1920 above

4 million pixels

20.3x25.4

12 inch 12x10

30.5x20.3

2500x2000 above

5 million pixels

25.4x30.5

15 inch 15x10

38.1x25.4

3000x2000

6 million pixels

25.4x38.1


Recently done project found that the same resolution of 2 machines, an interface style is not the same, after many tests found that the first pad (Lenovo a1_07) density of 1.5, converted to DPI is 240, belong to high-density; another pad has a density of 1, a medium density, Converted to DPI is 160, should be medium density
And that's the problem.Solving Method
Should be placed under the Values folder values-hdpi, values-mdpi respectively corresponding style, OK
Here are the learning materials
Screen resolution
Convert the physical DPI on the device to dips
Androidname approx. resolution multiply by this get dips
ldpi ~120 dpi 1.333
MDPI ~160 DPI 1.0 (Baseline density)
tvdpi ~213 dpi 0.751
hdpi ~240 DPI 0.67
xhdpi ~320 DPI 0.5

DPI: pixel pixels per inch (density *160)
Density: Density

Cell phone pixel density (density) is actually 160 pixels per inch as a reference standard, the main density is 0.75,1,1.5 and 2, when the density of 2 o'clock means 1 inches 320 pixels, Android code can get to the screen pixel value and density, Based on these values, the physical dimensions of the screen can be calculated backwards.

Screen size = pixel value of screen diagonal/(density *160) = [(long square + wide square) open root]/(density *160)

Practice Process

Because the density density obtained in the Android device itself is an approximately equal value, such as calculating the exact value of the density density=1.575, the density=1.5 that is actually read in the code, Need to implement a simple calculation of screen size applications on different devices to verify the accuracy of physical dimensions, the specific code is as follows:

Displaymetrics metric = new Displaymetrics ();
Getwindowmanager (). Getdefaultdisplay (). Getmetrics (Metric);
int width = metric.widthpixels; Screen width (in pixels)
int height = metric.heightpixels; Screen height (in pixels)
float density = metric.density; Screen Density (0.75/1.0/1.5)
int densitydpi = metric.densitydpi; Screen density dpi (120/160/240)
Double diagonalpixels = math.sqrt (Math.pow (width, 2) +math.pow (height, 2));
Double screensize = diagonalpixels/(160*density);

It's possible the size of the calculation screen is not too accurate.

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.