A comprehensive guide to understanding Android display properties, calculations, and ADB commands for developers.
Table of Contents
- Physical Size (Pixels)
- Density (DPI)
- Density-independent Pixels (dp)
- Smallest Width (sw)
- Minimum Width in Developer Options
- How They All Relate
- ADB Override Commands
- Practical Examples
- Quick Reference Tables
- 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:
| Bucket | DPI Range | Exact DPI | Scale Factor | Resource Folder |
|---|---|---|---|---|
| ldpi | ~120 | 120 | 0.75x | drawable-ldpi |
| mdpi | ~160 | 160 | 1.0x | drawable-mdpi |
| hdpi | ~240 | 240 | 1.5x | drawable-hdpi |
| xhdpi | ~320 | 320 | 2.0x | drawable-xhdpi |
| xxhdpi | ~480 | 480 | 3.0x | drawable-xxhdpi |
| xxxhdpi | ~640 | 640 | 4.0x | drawable-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 Type | Typical sw |
|---|---|
| Small phones | 320dp |
| Standard phones | 360dp |
| Large phones | 400dp |
| Phablets | 480dp |
| 7” tablets | 600dp |
| 10” tablets | 720dp |
| Desktop/Chrome OS | 840dp+ |
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
- Open Settings → Developer Options
- Scroll to “Smallest width”
- 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
| Property | Override Command | Effect |
|---|---|---|
| Size | wm size WxH | Changes reported resolution |
| Density | wm density DPI | Changes scaling, affects sw |
What You CANNOT Directly Set
| Property | Reason |
|---|---|
| sw (dp) | Calculated from size + density |
| dp dimensions | Calculated from pixels + density |
| Physical specs | Hardware 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 sw | Required Density | Command |
|---|---|---|
| 320dp | 360 dpi | adb shell wm density 360 |
| 360dp | 320 dpi | adb shell wm density 320 |
| 384dp | 300 dpi | adb shell wm density reset |
| 400dp | 288 dpi | adb shell wm density 288 |
| 480dp | 240 dpi | adb shell wm density 240 |
| 600dp | 192 dpi | adb shell wm density 192 |
| 720dp | 160 dpi | adb shell wm density 160 |
Density to sw Mapping (1080px Screen)
| Target sw | Required Density | Command |
|---|---|---|
| 320dp | 540 dpi | adb shell wm density 540 |
| 360dp | 480 dpi | adb shell wm density 480 |
| 400dp | 432 dpi | adb shell wm density 432 |
| 480dp | 360 dpi | adb shell wm density 360 |
| 540dp | 320 dpi | adb shell wm density 320 |
| 600dp | 288 dpi | adb shell wm density 288 |
| 720dp | 240 dpi | adb shell wm density 240 |
Density to sw Mapping (1440px Screen)
| Target sw | Required Density | Command |
|---|---|---|
| 360dp | 640 dpi | adb shell wm density 640 |
| 400dp | 576 dpi | adb shell wm density 576 |
| 480dp | 480 dpi | adb shell wm density 480 |
| 540dp | 426 dpi | adb shell wm density 426 |
| 600dp | 384 dpi | adb shell wm density 384 |
| 720dp | 320 dpi | adb shell wm density 320 |
Common ADB Settings Commands
| Setting | Command |
|---|---|
| Developer Options | adb shell am start -a android.settings.APPLICATION_DEVELOPMENT_SETTINGS |
| Display Settings | adb shell am start -a android.settings.DISPLAY_SETTINGS |
| Accessibility | adb shell am start -a android.settings.ACCESSIBILITY_SETTINGS |
| All Settings | adb shell am start -a android.settings.SETTINGS |
| App Info | adb shell am start -a android.settings.APPLICATION_DETAILS_SETTINGS -d package:<pkg> |
Font Scale Values
| Scale | Description | Command |
|---|---|---|
| 0.85 | Small | adb shell settings put system font_scale 0.85 |
| 1.0 | Default | adb shell settings put system font_scale 1.0 |
| 1.15 | Large | adb shell settings put system font_scale 1.15 |
| 1.30 | Largest | adb 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
- Pixels = Physical screen resolution (hardware)
- Density (dpi) = Pixels per inch, determines scaling
- dp = Virtual pixels, consistent physical size across devices
- sw = Smallest dimension in dp, used for layout selection
- 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)