Many netizens do not quite understand the difference between DP, SP, and PX: Here is a brief introduction.
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
In addition to density, SP is also not related to scale. If the screen density is 160, DP and SP are the same as PX. 1dp = 1sp = 1px, but if PX is used as the unit, the screen size remains unchanged (assuming
Or 3.2), and the screen density is 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
If DP and SP are used, the system will automatically convert according to the screen density change.