What is Px, Dp, Sp? Android Design Terms Measured
Measurement Units in Android Designs
In Android designs, layout, xml files, there are different units that we can use when we want to change the measurements in certain items. These are respectively;
- dp, dip – density independent pixels
- sp – scale independent pixels
- pt – points
- px – pixels
- mm – milimeters
- in – inches
What is Dp,Dip ?
Density is the abstract units depending on the physical density of the dp or dip device screen that we can translate as independent pixels.
We use dots per inch to complete this definition, which is the number of dots per inch. On a 160dpi screen, 1dp is equivalent to 1pixel. On a 320 dpi screen, 1dp will be equal to 2 pixels. Obviously dp is a proportional unit and is designed to capture the same proportions on different screens.
Dp Formula is calculated as follows;
dp = (pixel width * 160) / dpi
For example, for a 320 dpi android device with a 1200 pixel width, your width value would be 600 dp.
(1200 * 160) / 320 = 600dp
In the following code, a 20dp margin will be 20 pixels on a 160 dpi screen and 40 pixels on a 320 dpi screen.
What is Sp ?
The scale independent pixel is similar to the dp unit, and at the same time the user’s font size is related to the preference, so it is always advisable to use sp for defining font sizes.
What is Px?
Point per scale corresponds to actual pixels on the screen.
Millimeters – based on the physical size of the screen.
Inches – based on the physical size of the screen.
1 Inch = 2.54 centimeters