PickMe Jun 7, 2025

The Story of Pixels

Article Summary

Piyal Madushanka from PickMe breaks down why that 500x500px button looks completely different on your Pixel vs. your Samsung. The answer lies in understanding three deceptively simple concepts that every mobile developer uses but few truly understand.

This article demystifies the relationship between pixels, DPI, and density-independent pixels (DP) in Android development. Using clear visual examples and practical calculations, it explains why Android introduced DP as a solution to cross-device UI consistency challenges.

Key Takeaways

Critical Insight

Using DP instead of raw pixels is essential for building Android UIs that maintain consistent physical dimensions across devices with different screen densities.

The article includes side-by-side visual comparisons showing exactly how the same UI element transforms across different Android density buckets.

About This Article

Problem

Android developers ran into a problem where UI elements didn't look the same across different devices. A 500×500px image takes up different amounts of physical space on an mdpi screen versus an xhdpi screen because the pixel density varies.

Solution

Piyal Madushanka introduced density-independent pixels (DP) to fix this. The formula DP = Pixels / (DPI / 160) automatically scales UI dimensions based on each device's DPI compared to the 160 DPI baseline.

Impact

When developers use DP units instead of raw pixels, their interfaces maintain the same physical size across all screen densities. This removes the need to manually rework layouts for mdpi, hdpi, and xhdpi devices.