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.