Supporting Multiple Screens in Android

One of the biggest challenges in Android development is ensuring your app looks great on different screen sizes and densities. Android runs on thousands of devices — each with unique resolutions, DPIs, and aspect ratios — so understanding how to support multiple screens is essential for delivering a consistent user experience.


Understanding Screen Density

Screen density is the number of pixels within a physical area of the screen — measured as dots per inch (dpi).
It helps determine how UI elements and images scale across devices.

Note: Android measures screen size diagonally, i.e., from the bottom-left to the top-right corner of the display.

When you use density-independent pixels (dp) instead of pixels (px), Android automatically adjusts the size of your UI elements at runtime based on the device’s screen density.


Screen Density Categories and Conversion Ratios

Android groups devices into standard density buckets. Here’s how dp maps to px for each category:

DensityDPIConversion FormulaRatioExample (base 160)
ldpi120120 / 160 = 0.75x30.75 × dp = px
mdpi160160 / 160 = 1x41 × dp = px
hdpi240240 / 160 = 1.5x61.5 × dp = px
xhdpi320320 / 160 = 2x82 × dp = px
xxhdpi480480 / 160 = 3x123 × dp = px
xxxhdpi640640 / 160 = 4x164 × dp = px

The ratio between densities roughly becomes 0.75 : 1 : 1.5 : 2 : 3 : 4,
or when multiplied by 4 → 3 : 4 : 6 : 8 : 12 : 16.


Example: sw720dp Devices

  • sw720dp means a screen whose smallest width (in dp) is at least 720dp.
  • It’s often used for tablets and large-screen devices.

For example, you can create a layout specifically for tablets under:

res/layout-sw720dp/

Key Concepts to Remember

1. Use dp Instead of px

  • Always define sizes using density-independent pixels (dp).
  • This ensures your layout scales properly on devices with different screen densities. 1 dp = dpi / 160 pixels For mdpi (160 dpi) screens:
    1 dp = 1 px

2. Provide Alternative Resources

To make your app adaptive:

  • Provide multiple versions of layouts, drawables, and values for different densities.
  • Use the res/ directory qualifiers: res/drawable-ldpi/ res/drawable-mdpi/ res/drawable-hdpi/ res/drawable-xhdpi/ res/drawable-xxhdpi/ res/drawable-xxxhdpi/

Android will automatically pick the best matching resource folder based on the device configuration.


3. Let Android Handle Auto-Scaling

If density-specific images are missing, Android will auto-scale the available images to match the required density.
However, this can sometimes result in blurry or distorted images — so always prefer supplying proper density assets.


4. Use 9-Patch Images for Stretchable UI

Instead of providing multiple background images for different resolutions, use 9-patch drawables (.9.png files).
They scale intelligently while maintaining corners and edges.

Example use case:

  • Buttons
  • Dialog backgrounds
  • Cards and panels

✅ Example: Button background that stretches only in non-text areas.


5. Drawable Ratios for Common Icons

DensityExample Icon Size
ldpi36×36 px
mdpi48×48 px
hdpi72×72 px
xhdpi96×96 px
xxhdpi144×144 px
xxxhdpi192×192 px

Reference

Official Android Developer Guide:
Supporting Multiple Screens


Summary

ConceptDescription
Screen DensityNumber of pixels per inch (dpi)
dp (Density-independent pixel)Logical pixel unit that scales with screen density
swdp qualifierUsed for layouts based on smallest screen width
9-patch imagesScalable assets maintaining shape and corners
Multiple drawablesHelps maintain visual quality across devices

Key Takeaway

“Design for dp, not px** — and let Android handle the scaling magic.”

By following these best practices, your app will look beautiful and consistent across all Android devices — from small phones to large tablets.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top