Basic concepts of Screen for disgusting people

Source: Internet
Author: User

Among these basic concepts of Screen, dip is the most important, and dip is the key to understanding android adaptation to different devices.

 

Screen Size

Actual physical size. This is what we often call 3.5 inch screens and 4.7 inch screens. This length is the diagonal line length. In android, the physical size of the screen is divided into the following categories: small, normal, large, extra large. The following is a rough classification of the size and density. This figure may be updated as the actual device size and screen density keep increasing. For the latest figure, please go to the official website.

 

Figure 1

 

Resolution

"Screen" resolution, that is, the total number of pixels on the screen. Common expressions include 1280x720,192 0x1080.

 

 

Screen density

The screen density, which is the same as that expressed by dpi, is described in two different ways. The official website says:

 

Screen density

  • The quantity of pixels within a physical area of the screen; usually referred to as dpi (dots per inch ). for example, a "low" density screen has fewer pixels within a given physical area, compared to a "normal" or "high" density screen.

 

Public floatdensityThe logical density of the display.

Public intdensityDpiThe screen density expressed as dots-per-inch.

But in fact, I understand it as a scaling factor. The specific reason is explained later. By screen density, all mobile phones can be divided into the following categories:Ldpi(Low, low density ),Mdpi(Medium, standard density ),Hdpi(High, high density), andXhdpi(Extra high, super high density ).

 

DPI (dot per inch)

The number of records per inch. Both density and density describe the screen density. However, please note that this translation should be translated into dots per inch. To explain the cause, we have to introduce another concept: PPI (Pixel per inch), number of pixels per inch. The actual PPI is used in the computer display field, and DPI is used in the printing or printing field, but two concepts have been mixed since a long time ago:

"Points" are sometimes used to represent pixels, especially in the computer market. Because computer displays, such as LCD or CRT, are characterized by very small points, LCD displays are at standard screen resolutions, A pixel can be considered to be displayed by a "point" of the monitor, so the ppi is sometimes written as DPI (dots per inch, points per inch)-Wikipedia: pixel

In android, dpi is used to replace ppi to represent the pixel density.

 

 

DPI Calculation Method

Pixel density = Total number of pixels on the screen/screen size. We usually know that the screen size is 3.5 inch, 5.0 inch, and so on. This is the diagonal line length. We can first obtain the total number of pixels on the diagonal line and divide it by the diagonal line length.

Take Mi2s For example: 4.3 inch, 1280x720. The pixel value on the diagonal line can be √ (1280 ^ 2 + 720 ^ 2) ≈ 1468.6 according to the stock theorem, followed by 1468.6/4.3 ≈ 341.5

However, the test results from the Code seem to be biased:

Density: 2.0

DensityDpi: 320

Resolution: 1280x720

XDpi: 345.0566 // The number of pixels per inch in the x direction.

YDpi: 342.23157 // The number of pixels per inch in the y direction.

We can see that xDpi ≈ yDpi ≈ 341 is similar to our calculation result. But DensityDpi is 320. Why? As mentioned in Screen Density, android classifies the actual Density of all screens. The Density in a specific interval is a fixed value. See the following table:

 

Density Classification DPI value (pixel/inch) Density value
Ldpi
120 0.75
Mdpi 160 1
Hdpi
240 1.5
Xhdpi
320 2
Xxhdpi
480 3

Table 1

According to the classification in figure 1, the actual dpi of Mi2s is 341,341> 300, so Mi2s belongs to xhdpi. Combined with table 1, the DensityDpi = 320 is obtained.

The data above shows that the Density and DensityDpi values are different, but the rule is obvious. In android, mdpi is the standard value, and android sets its density to 1. The relationship between Density and DensityDpi is as follows: dpi = density * 160.

My question is, since dpi can represent the screen density, what should I do with density? To figure out the damn density, you must combine it with dp to look down.

 

Density-independent pixel (dip, or dp)

Independent pixel, virtual unit, or device independent pixel. The length of 1 DP is equivalent to the length of a physical pixel on a DPI screen. The DPI screen is the screen (mdpi) defined by android as the benchmark ). When the app is running, android converts dp to actual pixels for layout. The conversion formula is:Px = dp * (dpi/160).

 

Why dip?

Imagine that the app will deploy a chart in pixels, which is a PX square chart. When the app runs on 1920x1080, it looks relatively small, when running on 960x640, it looks very big, and the effect we want to see is that when the app runs on two mobile phones, this figure looks similar in size.

The following figure shows the layout in px units:

 

Figure 2

The following figure shows the effect of using the dp layout:

Figure 3

To achieve this, you need to zoom in on a high-density mobile phone and zoom in on a low-density mobile phone. However, we cannot predict the density and size of our app to be installed on a mobile phone. Even if we know it, we cannot prepare a set of pictures for each mobile phone. Therefore, we hope android can be smart, I set an approximate size. android can automatically adapt to different mobile phones. So there is an independent pixel unit. Obviously, developers only need to use dp or wrap_content directly, and the rest will be handed over to android. The system will scale your layout and images.

 

How does dp come from?

So how does android create this independent pixel?

First, our idea is to change the layout from the original layout with px to the layout with dp. Since the final dp still needs to be converted to px, the introduction of a coefficient λ includes: px = dp * λ, λ is our scaling factor;

Secondly, my final goal is to make all mobile phones see the same picture size, so how big is there to be a standard? I will choose a customized standard, make other mobile phones of different density display the same size as this standard. So I will set this standard to 160 pixels/inch. I will name it mdpi and classify other density mobile phones: ldpi (120 pixels/inch ), hdpi (240 pixels/inch), xhdpi (320 pixels/inch );

Once again, all categories are ready. Let's start scaling down:

When the app runs on a standard mobile phone (mdpi), the image should not be scaled because it is standard, that is, λ = 1, and px = dp;

When an app runs on a ldpi mobile phone, because the density is smaller than the standard, the image length is longer and the width is wider. To maintain the same length and width as the standard, the length of ldpi must be reduced to 120/160 = 0.75, and the width is also the same, that is, λ = 0.75, px = 0.75 * dp;

When the app runs on hdpi, λ = 1.5, px = 1.5 * dp;

And so on...

From the derivation above,Actually, Lambda = dpi/160 = density. It can be seen that density is lambda..

 

Conclusion

1. I learned from the official website that density and dpi both describe the screen density and seem to share the same concept. But why do we use two identical concepts to describe Obfuscation? I personally don't think we should distinguish them from the naming conventions. density is a scaling factor, while dpi is an accurate description of the density.Therefore, I only use dpi to indicate the screen density or pixel density, while density is actually the zoom coefficient or density coefficient;

2. Even images of the same size displayed by mobile phones of different density groups (such as xhdpi) are not the same for a closer look. After all, their density is different. Therefore, android only simplifies adaptation as much as possible. grouping cannot solve the adaptation problem.

 

SP

Font size for android. The original intention of sp is the same as that of dp, but it is applied to the font size.

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.