4. Screen Size & Density
• A set of four generalized sizes: small, normal, large, and xlarge
• xlarge screens are at least 960dp x 720dp
• large screens are at least 640dp x 480dp
• normal screens are at least 470dp x 320dp
• small screens are at least 426dp x 320dp
• A set of six generalized densities:
• ldpi (low) ~120dpi
• mdpi (medium) ~160dpi
• hdpi (high) ~240dpi
• xhdpi (extra-high) ~320dpi
• xxhdpi (extra-extra-high) ~480dpi
• xxxhdpi (extra-extra-extra-high) ~640dpi
5. How to Support Multiple Screens
1. Explicitly declare in the manifest which screen sizes your application
supports
2. Provide different bitmap drawables for different screen densities
3. Provide different layouts for different screen sizes
6. How to Support Multiple Screens(1)
“Explicitly declare in the manifest which screen sizes your application
supports”
• <supports-screens> element in your manifest file.
• Syntax : doc
<supports-screens android:resizeable=["true"| "false"]
android:smallScreens=["true" | "false"]
android:normalScreens=["true" | "false"]
android:largeScreens=["true" | "false"]
android:xlargeScreens=["true" | "false"]
android:anyDensity=["true" | "false"]
android:requiresSmallestWidthDp="integer"
android:compatibleWidthLimitDp="integer"
android:largestWidthLimitDp="integer"/>
7. How to Support Multiple Screens (2)
“Provide different bitmap drawables for different screen
densities”
• 3:4:6:8:12:16 scaling ratio
• For example, if you have a bitmap drawable that's 48x48 pixels for
medium-density screens.
• Where to put drawable resources:
• res/drawable-mdpi/graphic.png
• res/drawable-hdpi/graphic.png
• res/drawable-xhdpi/graphic.png
• res/drawable-xxhdpi/graphic.png
36*36
72*72
96 * 96
8. How to Support Multiple Screens (3)
“Provide different layouts for different screen sizes”
Put different layout res into different folder
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra-large screen size
res/layout-xlarge-land/my_layout.xml
How to name those folder ? configuration qualifiers
9. Configuration Qualifiers (1)
• Is: a string that you can append to a resource directory in your Android project and specifies the configuration
for which the resources inside are designed
• To: control how the system selects your alternative resources based on the characteristics of the current device
screen
• How: Create a new directory in your project's res/ directory and name it using the format:
<resources_name>-<qualifier>
• <resources_name> is the standard resource name:
drawable, layout, values
• <qualifier> is a configuration qualifier string !!!
12. Configuration Qualifiers (4)
• Qualifier name rules (doc)
• can specify multiple qualifiers for a single set of resources, separated by dashes:
drawable-en-rUS-land
• The qualifiers must be in the order listed above
• Alternative resource directories cannot be nested
• Values are case-insensitive
• Only one value for each qualifier type is supported
13. Decraling layout
The old way & new way
• The old way: put layout into res/layout-xlarge ( tablet)
• First generation, android 3.0
• The new way: base on amount of space you needed (such as you need 600dp of width)
• New qualifiers: smallestwidth, available width, available height
• sw<N>dp, w<N>dp, h<N>dp
• Typical screen width:
• 320dp: a typical phone screen (240x320 ldpi, 320x480 mdpi, 480x800 hdpi, etc).
• 480dp: a tweener tablet like the Streak (480x800 mdpi).
• 600dp: a 7” tablet (600x1024 mdpi).
• 720dp: a 10” tablet (720x1280 mdpi, 800x1280 mdpi, etc).
• So layout folder will be:
• res/layout/main_activity.xml # For handsets (smaller than 600dp available width)
• res/layout-sw600dp/main_activity.xml # For 7” tablets (600dp wide and bigger)
• res/layout-sw720dp/main_activity.xml # For 10” tablets (720dp wide and bigger)
• So new way of declaring screen size support in manifest
14. Best Practice
• Use wrap_content, match_parent, or dp units when specifying
dimensions in an XML layout file
• Do not use hard coded pixel values in your application code
• Do not use AbsoluteLayout (it's deprecated)
• Supply alternative bitmap drawables for different screen densities
17. Q & A
• allenlearntocode.com
• Allenatwork2012@gmail.com
Editor's Notes
Android supports several configuration qualifiers that allow you to control how the system selects your alternative resources based on the characteristics of the current device screen. A configuration qualifier is a string that you can append to a resource directory in your Android project and specifies the configuration for which the resources inside are designed.