Detailed description of length units in Android (DP, SP, PX, In, PT, mm)

Source: Internet
Author: User
This article is original. If you need to reprint it, please indicate the author and the source. Thank you!







Many netizens do not quite understand the difference between DP, SP, and PX: here we will introduce DP and sp. DP is dip. This is basically similar to sp. You can use DP to specify the length, height, and other attributes.
Or sp. If you set the font, you need to use sp. DP is not related to density. SP is not only related to density, but also to scale. If the screen density is 160, DP and SP and PX are one
. 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
If it is set to 320 PX, it is half shorter on a 3.2-inch screen with a density of 160 than on a 3.2-inch screen with a density. But if it is set to 160dp or 160sp. The system automatically
Set the width property value to 320px. That is, 160*320/160. Of these, 320/
160 can be called the density ratio factor. That is to say, if DP and SP are used, the system will automatically convert according to the screen density change.

Next, let's take a look at the meaning of other units.


Px: the actual pixel of the screen. For example, 320*480 screens have 320 pixels horizontally and 480 pixels vertically.

In: indicates the inch, which is the physical size of the screen. Each inch equals 2.54 cm. For example, the screen size of a mobile phone is often described as 3.2 (English), 3.5 (English), and 4 (English. These dimensions are the diagonal length of the screen. If the phone screen is 3.2 inch, the diagonal line length of the phone screen (visible area) is 3.2*2.54 = 8.128 cm. You can measure your mobile phone screen to see if the size is the same as the actual size.


MM: Indicates mm, which is the physical size of the screen.


PT: indicates a point, which is the physical size of the screen. The size is 1 inch of 1/72.

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.