Droid10

How to convert dp to px on Android

One formula, no lookup table needed: px = dp x (dpi / 160). A dp is defined as 1/160 of an inch, so the conversion depends only on the density the system reports, not on the phone's resolution alone.

dp value160 dpi (mdpi)320 dpi (xhdpi)480 dpi (xxhdpi)640 dpi (xxxhdpi)
16 dp — Small text / icon padding16 px32 px48 px64 px
48 dp — Minimum touch target48 px96 px144 px192 px
100 dp — Card width100 px200 px300 px400 px

The formula, step by step

Take the dp value, multiply it by the reported dpi, and divide by 160. For example, 48 dp on a 480 dpi phone is 48 x 480 / 160 = 144 px. On a 320 dpi phone the same 48 dp is 96 px. Both are about 7.6 mm on the glass, which is exactly why dp exists: the same layout stays physically consistent across very different panels.

To go the other way, divide px by the same factor: px / (dpi / 160) = dp. A 144 px element on a 480 dpi screen is 144 / 3 = 48 dp.

Non-standard densities still use the same formula

Not every phone reports one of the six standard buckets. A phone reporting 440 dpi still converts with the exact value: 16 dp is 16 x 440 / 160 = 44 px, and 48 dp is 132 px. Resource selection still snaps to the nearest bucket — 440 dpi reads drawable-xxhdpi — but pixel conversion uses the exact reported value. That distinction is why the dp to px converter accepts any dpi, not just 120, 160, 240, 320, 480 and 640.

Density buckets at a glance

The six standard buckets are listed below. They are the scale factors the system uses for drawable folders, and they are also the most common dpi values you will see in the wild.

dp, sp and px: which one to use

Use dp for layout sizes and spacing, sp for text, and px only when you need an exact pixel count, for example in a custom drawing routine. sp works like dp and then scales again with the user's font-size preference, so text set in sp can overflow a container measured in px if the user has enlarged system text.

To convert a real device, use the dp to px converter, check the device's reported density with adb shell wm density, or look it up in the device database. For the full bucket explanation, see density buckets and drawable folders.