Various android dimensions

Source: Internet
Author: User

 

 

The dimensions and sizes must be distinguished by the following units: dp, sp, pt, px, mm, in

 

Px: pixel, in the unit of pixel size. In the android UI, this unit is the same as the actual physical screen resolution, and is mainly used to display the definition effect.

 

 

 

Dp: Density-independent Pixels (device independent pixel), short for "dp", that is, dip. It is an abstract unit, because the physical screen is large and small, however, dp displays the same size on different physical screens, that is, it is only an abstract unit regardless of the screen size. In Android, you can use dip or dp, for example, android: layout_width = "88dp ".

 

Before talking about dip, we should first understand the concept of dpi. DPI: Dots per Inch, that is, the point contained in each Inch, 1 Inch is about 2.54, so the concept of dpi is easily formed in my mind. DPI is the unit used to describe the print density of the image. The higher the DPI, the more delicate and clear the printed image. In a computer with 72dpi, dpi is the number of pixels per inch. Dip is the pixel unit defined for a DPI screen, that is, 1px = 1dip on a DPI screen. the formula for converting dp to px is: px = dp * (density/160 ). For example, for a 4 inch screen with the same proportion, one is 160 dpi and the other is 320 dpi, then the width of 20px In the first screen will be twice that of the second screen, this results in a proportional imbalance, but if it is 20 DP, the first screen will occupy 20 PX, and the second screen will occupy 40 PX, with the same proportion of the screen width. Therefore, dp eliminates the impact of different types of screens on the layout.

 

 

 

How big is this dp? The official website explains that this dp unit is relative to a screen with a 160 dpi resolution (the Resolution here is the number of points per inch). Therefore, we say that no matter what the physical screen density is, 1 inch is equivalent to 160dp. If the resolution is 160 dpi, that is, 1 inch, we can see from the above formula:

 

Px = dp * (160 dpi/160 dpi)

 

Px = dp * (160dp/160dp)

 

Px = dp * 1

 

That is, 1dp = 1px

 

That is to say, on a 160-resolution screen, a dp is equal to one pixel.

 

 

 

Let's look at an example:

 

Assume that A mobile phone A has A resolution of 320*640 PX, and then the resolution of mobile phone B is * PX. The size of A and B is the same, then we know that cell phone B looks clearer. If we draw A button in both A and B, and we define that the button width is PX, then according to the above formula, the dp is inversely proportional to the resolution, the button in the dp of mobile phone A is larger, that is to say, the button we see in the UI interface of mobile phone A is larger than the button in mobile phone B; if we define that the button width is 100dp, then px is almost proportional to the resolution. The larger the Resolution, the larger the value calculated by px indicates that it looks clearer rather than bigger. Therefore, dp has nothing to do with the physical size of the screen, while px is used to indicate whether to see more clearly.

 

 

 

Sp: Scale-independent Pixels, which is a proportion-independent pixel. This is similar to dp, but mainly used to describe the font size. Therefore, sp is generally used to set the font size.

 

 

 

Pt: point. It indicates a point in Chinese and represents 1/72 of the size of physical screen 1.

 

 

 

Mm and in indicate millimeters and inches respectively, indicating the physical size of the screen.

 

 

 

Summary (in my opinion): dp is the size of the image to be displayed, while px is the definition. Therefore, in the view Design of android, dp is used instead of px. Dp is widely used. sp is mainly used for fonts, and others are rarely used.

 

 

 

 

 

The official website for these dimensions is:

 

Dimension

 

 

 

A dimension value defined in XML. A dimension is specified with a number followed by a unit of measure. For example: 10px, 2in, 5sp. The following units of measure are supported by Android:

 

 

 

Dp

 

Density-independent Pixels-an abstract unit that is based on the physical density of the screen. these units are relative to a 160 dpi (dots per inch) screen, so 160dp is always one inch regardless of the screen density. the ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. you shoshould use these units when specifying view dimensions in your layout, so the UI properly scales to render at the same actual size on different screens. (The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp ".)

 

Sp

 

Scale-independent Pixels-this is like the dp unit, but it is also scaled by the user's font size preference. it is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and the user's preference.

 

Pt

 

Points-1/72 of an inch based on the physical size of the screen.

 

Px

 

Pixels-corresponds to actual pixels on the screen. this unit of measure is not recommended because the actual representation can vary internal SS devices; each devices may have a different number of pixels per inch and may have more or fewer total pixels available on the screen.

 

Mm

 

Millimeters-based on the physical size of the screen.

 

In

 

Inches-based on the physical size of the screen.

 

Author: Feiyang cloud

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.