Length units in Android
1. Introduce dp and sp.
Dp is dip. This is basically similar to sp. You can use dp or sp to specify attributes such as length and height. 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 are the same as px.
1dp = 1sp = 1px
II. Introduction to px
However, if px is used as the unit, if the screen size remains unchanged (assumed to be 3.2), the screen density is changed to 320.
The original TextView width is set to 320 PX, And the 3.2-inch screen with a density of 160 is half shorter than the 3.2-inch screen with a density.
But if it is set to 160dp or 160sp. The system automatically sets the width property value to 320px. That is, 160*320/160.
Among them, 320/160 can be called the density proportion 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 meanings of other units px: indicating the actual pixels 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, it indicates the phone screen (visible area)
The diagonal line length 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.