Managing Multiple Screen Sizes and Densities for Android
Android supports different screen sizes and densities, hence to deal with this diversity certain range of buckets have been created based on these parameters.
1. Screen Density :
Screen density is the resolution of the device which is measured in dots per inch(dpi), below following are standard screen density buckets
LDPI: 0.75x or 75% (~120 DPI)
MDPI: 1x or 100% (base screen) (~160 DPI)
HDPI: 1.5x or 150% (~240 DPI)
XHDPI: 2x or 200% (~320 DPI)
XXHDPI: 3x or 300% (~480 DPI)
XXXHDPI: 4x or 400% (~640 DPI)
2. Screen Size :
Android classifies screens based on smallest- width qualifier. Based on the smallest width of a device, Android OS retrieves the layout from respective folders and inflates it on the screen i.e. res/layout, res/layout-sw600dp, and res/layout-sw720dp. Below following are screen size buckets
sw320dp
sw600dp
sw720p
sw1080p
Here important to note that, even if mobile devices share the same screen size, they can differ in terms of screen density.
In the development of a screen to support multiple form factors three components needs to take care
- Dimensions (TextSizes, Dialog dimensions, etc..)
- Image Assets Size
- Layout design
Dimensions:
Provide dimensions for each supported form factor in the values folder
values-xhdpi, values-xxhdpi , values-xxxhdpi ,values-hdpi ,values-mdpi, values-ldpi
values-sw720dp : 10.1” tablet
values-sw600dp : 7.0”. tablet
values-sw480dp : 5.4”, 5.1” device
values-sw1080dp: 15 ” device
Image Asset Size:
Png or Svg commonly we use in android applications, now based on screen density and screen size android picks image asset from respective drawable folder, so that image neither looks pixelated or small on the device.
If Pngs are used in the codebase, add drawable folders for relevant screen density and screen size buckets to support multiple form factors
For Ex: Image needs to be added in following screen density buckets to handle different screen resolutions
drawable-ldpi //240x320
drawable-mdpi //320x480
drawable-hdpi //480x800
drawable-xhdpi //720x1280
drawable-xxhdpi //1080X1920
drawable-xxxhdpi //1440X2560
To support different screen size , add drawables (sw600dp, sw720p , sw1080p ) for 7, 10 and 15 inch devices
For eg: Store images in below relevant drawable folders to handle image on 7 inch device
drawable-sw600dp_hdpi
drawable-sw600dp_mdpi
drawable-sw600dp_xhdpi
drawable-sw600dp_xxhdpi
drawable-sw600dp_xxxhdpi
Simlilarly to support image for 10 inch device add pngs in below folders
drawable-sw720dp_hdpi
drawable-sw720dp_mdpi
drawable-sw720dp_xhdpi
drawable-sw720dp_xxhdpi
drawable-sw720dp_xxxhdpi
If Svgs are used define dimensions for respective svg images in each values folder so as to support it on different form factors
Layout Design:
Based on the smallest width of a device, Android OS retrieves the layout from respective folders and inflates on the screen i.e. res/layout, res/layout-sw600dp and res/layout-sw720dp.
Here’s an illustrated example of the above procedure:
res/layout (for device dimensions: 640 x 360 dp.)
product_details.xml
res/layout-sw600dp (for device dimensions: 1024 x 600 dp.) 7” tables,
product_details.xml
res/layout-sw720dp (for device dimensions: 1280 x 800 dp.) 10” tablets
product_details.xml
Conclusion
Mobile developers creates different UI layouts so that to adapt wide-range of mobile devices with varying screen sizes and resolutions.