What are SP and DP in Android and How to Calculate the Resolution of a Device in DP

Generally, android uses dp and sp units for defining layout padding, margin, fixed layout height and width, text size, etc. The full form of DP and SP is density-independent pixels and scale-independent pixels respectively. Both dp and sp are used while creating android user interface (UI) in XML and also in java code. dp and sp are used in different purpose, dp is used for defining padding, margin, etc and sp is used for defining text size. To learn more about sp, dp and support multiple screen visit android developer site.

How to Calculate the Resolution of a Device in DP

Suppose, a seven inch android device have the density 213 dpi and the screen resolution in pixels is 1280 * 800 then to calculate the resolution in dp, apply following formula.

px/dp = dpi/160dpi
dp = px * 160dpi/dpi
dp = 1280 * 160 * 213
dp = 961.50


dp = px * 160dpi/dpi
dp = 800 * 160 * 213
dp = 600.93

The screen resolution of device in dp is 961.50 by 600.93
Tips-And-Tricks 8222343981271520041
Home item