Calculate DPI/PPI and determine density buckets for mobile devices
Screen density refers to the number of pixels within a physical area of the screen, typically measured as pixels per inch (PPI) or dots per inch (DPI). Higher density screens display sharper, more detailed images.
The number of pixels that fit into one inch of the screen. Calculated using the screen resolution and physical size:
PPI = √(width² + height²) / diagonal size
Technically different from PPI (used for printers), but the terms are often used interchangeably for screens. For mobile development, PPI is the more accurate term.
A virtual pixel unit that allows you to define UI elements in a way that's independent of screen density:
Physical Pixels = DP × Density Ratio
Android groups devices into density buckets to simplify resource management:
| Bucket | Qualifier | Ratio | PPI Range | Example |
|---|---|---|---|---|
| ldpi | ldpi | 0.75x | ~120 PPI | Older devices |
| mdpi | mdpi | 1.0x | ~160 PPI | Baseline density |
| hdpi | hdpi | 1.5x | ~240 PPI | Budget phones |
| xhdpi | xhdpi | 2.0x | ~320 PPI | Most smartphones |
| xxhdpi | xxhdpi | 3.0x | ~480 PPI | High-end phones |
| xxxhdpi | xxxhdpi | 4.0x | ~640 PPI | Premium devices |
iOS uses a simpler scale factor system:
| Scale | Multiplier | Examples |
|---|---|---|
| @1x | 1x | iPhone 3GS and earlier, iPad 2 |
| @2x | 2x | iPhone 4-8, iPhone SE, iPad (3rd gen+) |
| @3x | 3x | iPhone 6 Plus and later Plus/Pro Max models |
Place drawable resources in density-specific folders:
res/ drawable-ldpi/ drawable-mdpi/ drawable-hdpi/ drawable-xhdpi/ drawable-xxhdpi/ drawable-xxxhdpi/
Use naming conventions for different scales:
image.png (1x - 100×100) image@2x.png (2x - 200×200) image@3x.png (3x - 300×300)