Back to Articles
Android Display Metrics Guide for Developers

Android Display Metrics Guide for Developers

A comprehensive guide to understanding Android display properties, calculations, and ADB commands for developers.


Table of Contents

  1. Physical Size (Pixels)
  2. Density (DPI)
  3. Density-independent Pixels (dp)
  4. Smallest Width (sw)
  5. Minimum Width in Developer Options
  6. How They All Relate
  7. ADB Override Commands
  8. Practical Examples
  9. Quick Reference Tables
  10. Formula Cheat Sheet

1. Physical Size (Pixels)

The actual screen resolution in hardware pixels. This is the native resolution of the display panel.

Check Current Size

adb shell wm size

Example Output:

Physical size: 720x1600
  • 720 = width in pixels
  • 1600 = height in pixels

Key Points

  • This is determined by hardware (display panel)
  • Can be overridden via ADB for testing
  • Orientation changes swap width and height values
  • Higher pixel count = sharper display (given same physical size)

2. Density (DPI)

Density represents dots per inch (or pixels per inch). It determines the scaling factor between physical pixels and density-independent pixels (dp).

Check Current Density

adb shell wm density

Example Output:

Physical density: 300

Density Buckets

Android groups densities into standard buckets for resource selection:

BucketDPI RangeExact DPIScale FactorResource Folder
ldpi~1201200.75xdrawable-ldpi
mdpi~1601601.0xdrawable-mdpi
hdpi~2402401.5xdrawable-hdpi
xhdpi~3203202.0xdrawable-xhdpi
xxhdpi~4804803.0xdrawable-xxhdpi
xxxhdpi~6406404.0xdrawable-xxxhdpi

The Baseline

  • mdpi (160 dpi) is the baseline density
  • At mdpi: 1 dp = 1 pixel
  • All other densities scale relative to this

Scale Factor Calculation

scale_factor = device_dpi / 160

Example (300 dpi device):

scale_factor = 300 / 160 = 1.875

This means 1 dp = 1.875 pixels on this device.


3. Density-independent Pixels (dp)

A dp (also written as dip) is a virtual pixel unit that provides a consistent size across different screen densities.

Why dp Exists

Without dp, a 100-pixel button would be:

  • Tiny on a 640 dpi phone
  • Huge on a 160 dpi tablet

With dp, a 100dp button appears the same physical size on all devices.

Conversion Formulas

Pixels to dp:

dp = pixels / (density / 160)
dp = pixels / scale_factor

dp to Pixels:

pixels = dp × (density / 160)
pixels = dp × scale_factor

Example Calculation

Device: 720x1600 pixels at 300 dpi

width_dp  = 720 / (300 / 160) = 720 / 1.875 = 384 dp
height_dp = 1600 / (300 / 160) = 1600 / 1.875 = 853 dp

So the screen is 384 x 853 dp.


4. Smallest Width (sw)

The smallest width is the minimum of the screen’s width and height in dp. It’s called “smallest” because it represents the narrowest dimension regardless of orientation.

Calculation

sw = min(width_dp, height_dp)

Example

Device: 384 x 853 dp

sw = min(384, 853) = 384 dp

This device qualifies as sw384dp.

Key Characteristics

  • Rotation-independent: sw stays the same in portrait or landscape
  • Used for layouts: Determines which layout resources to load
  • Fixed relationship: Directly tied to physical size and density

Resource Qualifiers

Use sw qualifiers to provide different layouts:

res/
├── layout/                  # Default (all devices)
├── layout-sw320dp/          # Small phones (320dp+)
├── layout-sw360dp/          # Medium phones (360dp+)
├── layout-sw400dp/          # Large phones (400dp+)
├── layout-sw600dp/          # 7" tablets (600dp+)
├── layout-sw720dp/          # 10" tablets (720dp+)
└── layout-sw840dp/          # Large tablets (840dp+)

Common Device Smallest Widths

Device TypeTypical sw
Small phones320dp
Standard phones360dp
Large phones400dp
Phablets480dp
7” tablets600dp
10” tablets720dp
Desktop/Chrome OS840dp+

5. Minimum Width (Developer Options)

The “Smallest width” setting in Android Developer Options allows you to override the calculated sw value for testing purposes.

How to Access

  1. Open Settings → Developer Options
  2. Scroll to “Smallest width”
  3. Enter desired dp value

Via ADB

# Open Developer Options
adb shell am start -a android.settings.APPLICATION_DEVELOPMENT_SETTINGS

What Happens Internally

When you enter a value (e.g., 600), Android calculates the required density:

new_density = (min_physical_pixels / entered_sw) × 160

Example: Enter 600 on a 720px wide screen:

new_density = (720 / 600) × 160 = 192 dpi

Android then applies this density override.


6. How They All Relate

The Relationship Diagram

┌─────────────────────────────────────────────────────────────┐
│                      PHYSICAL LAYER                         │
│                   (Hardware - Fixed)                        │
│                                                             │
│              Screen Resolution: 720 × 1600 px               │
│              Physical Density: 300 dpi                      │
└─────────────────────────┬───────────────────────────────────┘

                          │  Conversion: dp = px / (dpi / 160)


┌─────────────────────────────────────────────────────────────┐
│                      VIRTUAL LAYER                          │
│                  (Software - Calculated)                    │
│                                                             │
│              Screen Size: 384 × 853 dp                      │
│              Smallest Width: 384 dp                         │
└─────────────────────────────────────────────────────────────┘

                          │  Resource Selection


┌─────────────────────────────────────────────────────────────┐
│                     RESOURCE LAYER                          │
│                   (Layout Selection)                        │
│                                                             │
│              Uses: layout-sw384dp (if exists)               │
│              Falls back to: layout-sw360dp or layout/       │
└─────────────────────────────────────────────────────────────┘

The Master Formula

                    min(width_px, height_px)
Smallest Width = ─────────────────────────────
                       density / 160

Rearranged to find density for a target sw:

                   min(width_px, height_px) × 160
Required Density = ─────────────────────────────────
                          target_sw

7. ADB Override Commands

Size Override

# Set custom size
adb shell wm size 1080x1920

# Check current (shows override if set)
adb shell wm size

# Reset to physical
adb shell wm size reset

Density Override

# Set custom density
adb shell wm density 480

# Check current (shows override if set)
adb shell wm density

# Reset to physical
adb shell wm density reset

Reset Everything

# Reset both size and density
adb shell wm size reset && adb shell wm density reset

What You CAN Override

PropertyOverride CommandEffect
Sizewm size WxHChanges reported resolution
Densitywm density DPIChanges scaling, affects sw

What You CANNOT Directly Set

PropertyReason
sw (dp)Calculated from size + density
dp dimensionsCalculated from pixels + density
Physical specsHardware limitation

8. Practical Examples

Example Device Specs

Physical Size: 720 × 1600 pixels
Physical Density: 300 dpi
Calculated sw: 384 dp

Simulate Different Devices

Simulate sw320dp (Small Phone)

# Calculate: density = (720 / 320) × 160 = 360
adb shell wm density 360

Verification:

sw = 720 / (360 / 160) = 720 / 2.25 = 320 dp ✓

Simulate sw360dp (Standard Phone)

# Calculate: density = (720 / 360) × 160 = 320
adb shell wm density 320

Verification:

sw = 720 / (320 / 160) = 720 / 2.0 = 360 dp ✓

Simulate sw400dp (Large Phone)

# Calculate: density = (720 / 400) × 160 = 288
adb shell wm density 288

Verification:

sw = 720 / (288 / 160) = 720 / 1.8 = 400 dp ✓

Simulate sw480dp (Phablet)

# Calculate: density = (720 / 480) × 160 = 240
adb shell wm density 240

Verification:

sw = 720 / (240 / 160) = 720 / 1.5 = 480 dp ✓

Simulate sw600dp (7” Tablet)

# Calculate: density = (720 / 600) × 160 = 192
adb shell wm density 192

Verification:

sw = 720 / (192 / 160) = 720 / 1.2 = 600 dp ✓

Simulate sw720dp (10” Tablet)

# Calculate: density = (720 / 720) × 160 = 160
adb shell wm density 160

Verification:

sw = 720 / (160 / 160) = 720 / 1.0 = 720 dp ✓

Simulate Higher Resolution

Keep the same sw but increase sharpness:

adb shell wm size 1080x2400
adb shell wm density 450

Calculation:

sw = 1080 / (450 / 160) = 1080 / 2.8125 = 384 dp

Same sw (384dp), but with 1.5x more pixels!


9. Quick Reference Tables

Density to sw Mapping (720px Screen)

Target swRequired DensityCommand
320dp360 dpiadb shell wm density 360
360dp320 dpiadb shell wm density 320
384dp300 dpiadb shell wm density reset
400dp288 dpiadb shell wm density 288
480dp240 dpiadb shell wm density 240
600dp192 dpiadb shell wm density 192
720dp160 dpiadb shell wm density 160

Density to sw Mapping (1080px Screen)

Target swRequired DensityCommand
320dp540 dpiadb shell wm density 540
360dp480 dpiadb shell wm density 480
400dp432 dpiadb shell wm density 432
480dp360 dpiadb shell wm density 360
540dp320 dpiadb shell wm density 320
600dp288 dpiadb shell wm density 288
720dp240 dpiadb shell wm density 240

Density to sw Mapping (1440px Screen)

Target swRequired DensityCommand
360dp640 dpiadb shell wm density 640
400dp576 dpiadb shell wm density 576
480dp480 dpiadb shell wm density 480
540dp426 dpiadb shell wm density 426
600dp384 dpiadb shell wm density 384
720dp320 dpiadb shell wm density 320

Common ADB Settings Commands

SettingCommand
Developer Optionsadb shell am start -a android.settings.APPLICATION_DEVELOPMENT_SETTINGS
Display Settingsadb shell am start -a android.settings.DISPLAY_SETTINGS
Accessibilityadb shell am start -a android.settings.ACCESSIBILITY_SETTINGS
All Settingsadb shell am start -a android.settings.SETTINGS
App Infoadb shell am start -a android.settings.APPLICATION_DETAILS_SETTINGS -d package:<pkg>

Font Scale Values

ScaleDescriptionCommand
0.85Smalladb shell settings put system font_scale 0.85
1.0Defaultadb shell settings put system font_scale 1.0
1.15Largeadb shell settings put system font_scale 1.15
1.30Largestadb shell settings put system font_scale 1.30

Check current: adb shell settings get system font_scale


10. Formula Cheat Sheet

Core Conversions

┌────────────────────────────────────────────────────────────┐
│  PIXELS ←→ DP                                              │
│                                                            │
│  dp = pixels ÷ (density ÷ 160)                             │
│  pixels = dp × (density ÷ 160)                             │
└────────────────────────────────────────────────────────────┘

┌────────────────────────────────────────────────────────────┐
│  SMALLEST WIDTH                                            │
│                                                            │
│  sw = min(width_px, height_px) ÷ (density ÷ 160)           │
└────────────────────────────────────────────────────────────┘

┌────────────────────────────────────────────────────────────┐
│  DENSITY FOR TARGET SW                                     │
│                                                            │
│  density = (min_pixels ÷ target_sw) × 160                  │
└────────────────────────────────────────────────────────────┘

┌────────────────────────────────────────────────────────────┐
│  SCALE FACTOR                                              │
│                                                            │
│  scale = density ÷ 160                                     │
└────────────────────────────────────────────────────────────┘

Quick Mental Math

For a 720px screen:

  • sw600 → density ≈ 190
  • sw480 → density = 240
  • sw360 → density = 320
  • sw320 → density = 360

For a 1080px screen:

  • sw600 → density ≈ 290
  • sw480 → density = 360
  • sw360 → density = 480
  • sw320 → density = 540

Summary

  1. Pixels = Physical screen resolution (hardware)
  2. Density (dpi) = Pixels per inch, determines scaling
  3. dp = Virtual pixels, consistent physical size across devices
  4. sw = Smallest dimension in dp, used for layout selection
  5. Override density to simulate different sw values for testing

The Key Insight

You cannot set sw directly. Instead:

To change sw → Change density
Lower density → Higher sw (tablet-like)
Higher density → Lower sw (small phone-like)