1 page.title=Supporting Multiple Screens 2 3 @jd:body 4 5 <div id="qv-wrapper"> 6 <div id="qv"> 7 8 <h2>Quickview</h2> 9 <ul> 10 <li>Android runs on devices that have different screen sizes and resolutions.</li> 11 <li>The screen on which your application is displayed can affect its user interface.</li> 12 <li>The platform handles most of the work of adapting your app to the current screen.</li> 13 <li>You can create screen-specific resources for precise control of your UI, if needed. </li> 14 <li>Older applications run in a compatibility mode that provides best-effort rendering on the current screen.</li> 15 <li>It's important to follow the best practices described in this document and test your application in all supported screens. </li> 16 </ul> 17 18 <h2>In this document</h2> 19 <ol> 20 <li><a href="#overview">Overview of Screen Support</a></li> 21 <ol> 22 <li><a href="#range">Range of screens supported</a></li> 23 <li><a href="#support">How Android supports multiple screens</a></li> 24 <li><a href="#density-independence">Density independence</a></li> 25 <li><a href="#attrs">Manifest attributes</a></li> 26 <li><a href="#qualifiers">Resource qualifiers</a></li> 27 </ol> 28 <li style="padding-top:4px;"><a href="#screen-independence">Best Practices for Screen Independence</a></li> 29 <li><a href="#strategies">Strategies for Legacy Apps</a></li> 30 <li><a href="#testing">How to Test Your App</a></li> 31 32 </ol> 33 34 <h2>See Also</h2> 35 <ol> 36 <li><code><a href="{@docRoot}guide/topics/manifest/supports-screens-element.html"><supports-screens></a></code></li> 37 <li><code><a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html"><uses-sdk></a></code></li> 38 <li><a href="{@docRoot}guide/topics/resources/providing-resources.html#AlternativeResources">Alternative Resources</a></li> 39 <li><a href="{@docRoot}guide/developing/tools/avd.html">Android Virtual Devices</a></li> 40 </ol> 41 42 </div> 43 </div> 44 45 <p>Android is designed to run on a variety of devices that offer a range of 46 screen sizes and resolutions. For applications, the platform provides a 47 consistent environment across devices and handles much of the complexity of 48 adapting an application's UI to the screen on which it is being displayed. At 49 the same time, the platform exposes APIs that give application developers 50 precise control over their application's UI when displayed on specific screen 51 sizes and resolutions. </p> 52 53 <p>This document explains the screens-support features provided by the platform 54 and how you use them in your application. By following the practices described 55 here, you can easily create an application that displays properly on all 56 supported device screens and that you can deploy to any device as a single .apk. 57 </p> 58 59 <p>If you have already developed and published an application for Android 1.5 or 60 earlier, you should read this document and consider how you may need to adapt 61 your application for proper display on new devices that offer different screens 62 and that are running Android 1.6 or later. In most cases, only minor adjustments 63 are needed, however you should make sure to <a href="#testing">test your 64 application</a> on all supported screens. </p> 65 66 <p>In particular, if you have an existing application that you would like to 67 make available for users of devices with small screens (such as QVGA), please 68 see <a href="#strategies">Strategies for Legacy Applications</a> for more 69 information about how to do that. </p> 70 71 72 <h2 id="overview">Overview of Screens Support</h2> 73 74 <p>The sections below provide an overview of the Android platform's support for 75 multiple screens, including an introduction to terms and concepts used in this 76 document and in the API, a summary of the screen configurations that the 77 platform supports, and an overview of the API and underlying 78 screen-compatibility features.</p> 79 80 81 <h3>Terms and Concepts</h3> 82 83 <dl> 84 <dt><em>Screen size</em></dt> 85 <dd>Actual physical size, measured as the screen's diagonal. 86 87 <p>For simplicity, Android collapses all actual screen sizes into three 88 generalized sizes: large, normal, and small. Applications can provide custom 89 layouts for each of these three sizes — the platform transparently handles 90 the rendering of the layouts at the actual screen size.</p></dd> 91 92 <dt><em>Aspect ratio</em></dt> 93 <dd>The porportional relationship of the screen's physical width to its 94 height. Applications can provide layout resources for specific aspect ratios by 95 using the resource qualifiers <code>long</code> and <code>notlong</code>. </dd> 96 97 <dt><em>Resolution</em></dt> 98 <dd>The total number of physical pixels on a screen. Note that, although 99 resolution is often expressed as <em>width</em> x <em>height</em>, resolution 100 does not imply a specific aspect ratio. In Android, applications do not work 101 directly with resolution.</dd> 102 103 <dt><em>Density</em></dt> 104 <dd>Based on the screen resolution, the spread of pixels across the physical 105 width and height of the screen. 106 107 <p>A screen with lower density has fewer available pixels spread across the 108 screen width and height, where a screen with higher density has more — 109 sometimes significantly more — pixels spread across the same area. The 110 density of a screen is important because, other things being equal, a UI element 111 (such as a button) whose height and width are defined in terms of screen pixels 112 will appear larger on the lower density screen and smaller on the higher density 113 screen. </p> 114 115 <p>For simplicity, Android collapses all actual screen densities into three 116 generalized densities: high, medium, and low. Applications can provide custom 117 resources for each of these three densities — the platform handles the 118 scaling of the resources up or down to meet the actual screen density. </p></dd> 119 <dt><em>Density-independent pixel (dip)</em></dt> 120 <dd>A virtual pixel unit that applications can use in defining their UI, to 121 express layout dimensions or position in a density-independent way. 122 <p>The density-independent pixel is equivalent to one physical pixel on a 160 123 dpi screen, the baseline density assumed by the platform (as described later in 124 this document). At run time, the platform transparently handles any scaling of 125 the dip units needed, based on the actual density of the screen in use. The 126 conversion of dip units to screen pixels is simple: <code>pixels = dips * 127 (density / 160)</code>. For example, on 240 dpi screen, 1 dip would equal 1.5 128 physical pixels. Using dip units to define your application's UI is highly 129 recommended, as a way of ensuring proper display of your UI on different 130 screens. </p></dd> 131 </dl> 132 133 134 <h3 id="range">Range of screens supported</h3> 135 136 <p>Starting from Android 1.6, the platform provides support for multiple screen 137 sizes and resolutions, reflecting the many new types and sizes of devices on 138 which the platform runs. If you are developing an application that will run 139 on Android 1.6 or later, you can use the compatibility features of the Android 140 platform to ensure that your application UI renders properly across the range of 141 supported screen sizes and resolutions.</p> 142 143 <p>To simplify the way that developers design their user interfaces for 144 multiple devices and to allow more devices to participate without affecting 145 applications, the platform divides the range of actual supported screen sizes 146 and resolutions into:</p> 147 148 <ul> 149 <li>A set of three generalized sizes: <em>large</em>, <em>normal</em>, and <em>small</em>, and </li> 150 <li>A set of three generalized densities: <em>hdpi</em> (high), <em>mdpi</em> (medium), and <em>ldpi</em> (low) 151 </ul> 152 153 <p>Applications can provide custom resources (primarily layouts) for any of the 154 three generalized sizes and can provide resources (primarily drawables such as 155 images) for any of the three generalized densities. Applications do not need to 156 work with the actual physical size or density of the device screen. At run time, 157 the platform handles the loading of the correct size or density resources, based 158 on the generalized size or density of the current device screen, and adapts them 159 to the actual pixel map of the screen.</p> 160 161 <p>The generalized size/density configurations are arranged around a 162 baseline configuration that is assigned a size of <em>normal</em> and a density of 163 <em>mdpi</em> (medium). All applications written for Android 1.5 or earlier are (by 164 definition) designed for the baseline HVGA screen used on the T-Mobile G1 and 165 similar devices, which is size <em>normal</em> and density 166 <em>mdpi</em>.</p> 167 168 <p>Each generalized screen configuration spans a range of actual screen 169 densities and physical sizes. For example, that means that multiple devices that 170 report a screen size of <em>normal</em> might offer screens that differ slightly 171 in actual size or aspect ratio. Similarly, devices that report a screen density 172 of <em>hdpi</em> might offer screens with slightly different pixel densities. 173 The platform makes these differences abstract, however — applications can 174 offer UI designed for the generalized sizes and densities and let the system 175 handle the actual rendering of the UI on the current device screen according to 176 its characteristics. </p> 177 178 179 <img src="{@docRoot}images/screens_support/screens-ranges.png" /> 180 <p class="img-caption"><strong>Figure 1.</strong> 181 Illustration of how the Android platform maps actual screen densities and sizes 182 to generalized density and size configurations. </p> 183 184 <p>Although the platform lets your application provide layouts and resources for 185 generalized size-density configurations, you do not necessarily need to do write 186 custom code or provide custom resources for each of the nine supported 187 configurations. The platform provides robust compatibility features, described 188 in the sections below, that can handle most of the work of rendering your 189 application on any device screen, provided that you've implemented your 190 application UI properly. For more information about how to implement a UI that 191 renders properly across device screens and platform versions, see 192 <a href="#screen-independence">Best Practices for Screen Independence</a>.</p> 193 194 <p>To help you test your applications, the Android SDK includes emulator skins 195 that replicate the sizes and densities of actual device screens on which your 196 application is likely to run. You can also modify the default size and density 197 of the emulator skins to replicate the characteristics of any specific 198 screen.</p> 199 200 <p class="table-caption" id="screens-table"><strong>Table 1.</strong> Screen 201 sizes and densities of emulator skins included in the Android SDK.</p> 202 203 <table id="screens-table"> 204 <tbody> 205 <tr> 206 <td style="border:none"></td> 207 <td style="background-color:#f3f3f3"> 208 <nobr>Low density (120), <em>ldpi</em></nobr> 209 </td> 210 <td style="background-color:#f3f3f3"> 211 <nobr>Medium density (160), <em>mdpi</em></nobr> 212 </td> 213 <td style="background-color:#f3f3f3"> 214 <nobr>High density (240), <em>hdpi</em><nobr> 215 </td> 216 </tr> 217 <tr> 218 <td style="background-color:#f3f3f3"> 219 <em>Small</em> screen 220 </td> 221 <td style="font-size:.9em;">QVGA (240x320)</td> 222 </td> 223 <td></td> 224 <td></td> 225 </tr> 226 <tr> 227 <td style="background-color:#f3f3f3"> 228 <em>Normal</em> screen 229 </td> 230 <td style="font-size:.9em;">WQVGA400 (240x400)<br>WQVGA432 (240x432)</td> 231 <td style="font-size:.9em;">HVGA (320x480)</td> 232 <td style="font-size:.9em;">WVGA800 (480x800)<br>WVGA854 (480x854)</td> 233 </tr> 234 <tr> 235 <td style="background-color:#f3f3f3"> 236 <em>Large</em> screen 237 </td> 238 <td></td> 239 <td style="font-size:.9em;">WVGA800* (480x800)<br>WVGA854* (480x854)</td> 240 <td></td> 241 </tr> 242 <tr> 243 <td colspan="4" style="border:none;font-size:90%;">* To emulate this 244 configuration, specify a custom density of 160 when 245 creating an AVD that uses a WVGA800 or WVGA854 skin. 246 </td> 247 </table> 248 249 <p>For an overview of the relative numbers of high (hdpi), medium (mdpi), and 250 low (ldpi) density screens in Android-powered devices available now, see the <a 251 href="{@docRoot}resources/dashboard/screens.html">Screen Sizes and Densities</a> dashboard.</p> 252 253 254 <h3 id="support">How Android supports multiple screens</h3> 255 256 <div class="sidebox-wrapper"> 257 <div class="sidebox"> 258 <h2>Using the alternative resources framework</h2> 259 260 <p>The platform's support for loading screen size- and density-specific 261 resources at run time is based on the alternative resources framework. 262 263 <p> If you want to use size- or density-specific layouts or drawables in your 264 application and you are not familiar with resource qualifiers or how the 265 platform uses them, please read 266 <a href="{@docRoot}guide/topics/resources/providing-resources.html#AlternativeResources"> 267 Alternative Resources</a>. 268 </div> 269 </div> 270 271 <p>The foundation of Android's support for multiple screens is a set of built-in 272 compatibility features that together manage the rendering of application 273 resources in an appropriate way for the current device screen. The platform 274 handles most of the work of rendering your application, but also gives you two 275 key ways to control how your application is displayed, if you need or want 276 to use them:</p> 277 278 <ul> 279 <li>The platform supports a set of resource qualifiers that let you provide 280 size- and density-specific resources, if needed. The qualifiers for 281 size-specific resources are <code>large</code>, <code>normal</code>, and 282 <code>small</code>, and those for density-specific resources are 283 <code>hdpi</code> (high), <code>mdpi</code> (medium), and <code>ldpi</code> 284 (low). The qualifiers correspond to the generalized densities described in 285 <a href="#range">Range of screens supported</a>, above.</li> 286 <li>The platform also provides a 287 <a href="{@docRoot}guide/topics/manifest/supports-screens-element.html"> 288 <code><supports-screens></code></a> 289 manifest element, whose attributes 290 <code>android:largeScreens</code>, <code>android:normalScreens</code>, and 291 <code>android:smallScreens</code> let you specify what generalized screen sizes 292 your application supports. A fourth attribute, <code>android:anyDensity</code>, 293 lets you indicate whether or not your application includes built-in support for 294 multiple densities.</li> 295 </ul> 296 297 <p>At run time, the platform provides three types of support to your 298 application, to ensure the best possible display on the current device 299 screen:</p> 300 301 <ol> 302 <li><em>Pre-scaling of resources (such as image assets)</em> 303 304 <p>Based on the density of the current screen, the platform automatically 305 loads any size- or density-specific resources from your application and displays 306 them without scaling. If no matching resources are available, the platform loads 307 the default resources and scales them up or down as needed to match the current 308 screen's generalized density. The platform assumes that default resources are 309 designed for proper display at the baseline screen density of "medium" (160), 310 unless they are loaded from a density-specific resource directory.</p> 311 312 <p>For example, if the current screen's density is "high", the platform loads 313 resources that are tagged with the qualifier <code>hdpi</code> and uses them 314 without scaling. If no such resources are available, the platform uses the 315 default resources instead, scaling them from the baseline density ("medium") to 316 "high". </p> 317 318 <p>For more information about how to create size- and density-specific 319 resources, see <a href="#qualifiers">Resource qualifiers</a>.</p></li> 320 321 <li><em>Auto-scaling of pixel dimensions and coordinates</em> 322 323 <p>If the application states that it does not support different screen 324 densities, the platform auto-scales any absolute pixel coordinates, pixel 325 dimension values, and pixel math used in the application (such as might be used 326 for specifying the width or padding for a view). It does this to ensure that 327 pixel-defined screen elements are displayed at approximately the same physical 328 size as they would be at the baseline density of "medium" (160). The platform 329 handles this scaling transparently to the application and also reports scaled 330 overall pixel dimensions to the application, rather than physical pixel 331 dimensions. </p> 332 333 <p>For instance, suppose a given device is using a WVGA high-denisty screen, 334 which is 480x800 and about the same size as a traditional HVGA screen, but it's 335 running an app that states that it does not support multiple densities. In this 336 case, the system will "lie" to the application when it queries for screen 337 dimensions, and report 320x533. Then, when the app does drawing operations, such 338 as invalidating the rectangle from (10,10) to (100, 100), the system will 339 likewise automatically transform the coordinates by scaling them the appropriate 340 amount, and actually invalidate the region (15,15) to (150, 150). The same 341 thing happens in the other direction, if the application is running on a 342 lower-density screen, coordinates are scaled down.<p> 343 344 <p>For more information, see the <code>android:anyDensity</code> attribute in 345 <a href="#attrs">Manifest attributes for screens support</a>.</p></li> 346 347 <div class="sidebox-wrapper" xstyle="margin-bottom:2em;margin-top:.5em;width:90%;"> 348 <img id="rule" src="{@docRoot}assets/images/grad-rule-qv.png"> 349 <div id="qv-sub-rule"> 350 <img src="{@docRoot}assets/images/icon_market.jpg" style="float:left;margin:0;padding:0;"> 351 <p style="color:#669999;">Publishing to Small Screen Devices</p> 352 <p>To ensure the best experience for users on small-screen devices, Android 353 Market only shows applications that explicitly declare support for small 354 screens. If you developed an application on Android 1.5 or earlier and published 355 it on Android Market, you need to <a href="#testing">test your application</a> 356 on small screens and then upload an updated version that explicitly 357 <a href="#attrs">indicates support for small screens</a>. </p> 358 </div> 359 </div> 360 361 <li><em>Compatibility-mode display on larger screen-sizes</em> 362 363 <p>If the current screen's size is larger than your application supports, as 364 specified in the <code>supports-screens</code> element, the platform displays 365 the application at the baseline size ("normal") and density ("medium). For 366 screens larger than baseline, the platform displays the application in a 367 baseline-sized portion of the overall screen, against a black background. </p> 368 369 <p>For instance, suppose a given device is using a WVGA medium density screen, 370 classified as a "large" screen, but the application states that it does not 371 support large screens; in this case, the system will again "lie" to the 372 application when it queries for screen dimensions, and report 320x480. Instead 373 of scaling the application, however, the application's 320x480 interface will be 374 placed as a "postage stamp" in the larger 480x800 screen.</p> 375 376 <p>For more information, see the <code>android:anyDensity</code> attribute in 377 <a href="#attrs">Manifest elements for screens support</a> and the 378 <a href="#compatibility-examples">Screen-Compatibility Examples</a> 379 section.</p></li> 380 </ol> 381 382 <p>In general, these compatibility features ensure that all applications, 383 including those written against Android 1.5 and earlier platform versions, can 384 display properly on most devices, especially when the device's screen is at the 385 baseline "normal" size or larger. </p> 386 387 <p>However, note that applications written for the baseline screen may need 388 minor adjustments before they display properly on smaller screens such as QVGA. 389 With the reduced screen area of small screens, there may be tradeoffs in design, 390 content, and function that you, as the application developer, need to consider. 391 For more information about how to prepare an existing application for display on 392 small screens, see <a href="#strategies">Strategies for Legacy 393 Applications</a>.</p> 394 395 <p>The sections below provide more information how to take advantage of the 396 platform's multiple-screens support. </p> 397 398 399 <h3 id="density-independence">Density independence</h3> 400 401 <p>The goal of density independence is to preserve the physical size, from the 402 user's point of view, of user interface elements declared in an application, 403 when the application is displayed on screens with different densities. Density 404 independence applies to both layouts and drawables such as icons. Maintaining 405 density-independence is important because, other things being equal, a UI 406 element (such as a button) whose height and width are defined in terms of screen 407 pixels will appear physically larger on the lower density screen and smaller on 408 the higher density screen. Such density-related size changes can cause problems 409 in application layout, usability, and consistency with other applications 410 installed on the device.</p> 411 412 <p>The platform provides density independence to applications by default. It 413 does this in three ways: </p> 414 415 <ul> 416 <li>Through pre-scaling of drawable resources (scaled at resource loading 417 time)</li> 418 <li>Through auto-scaling of density-independent pixel (dip) values used in 419 layouts</li> 420 <li>Through auto-scaling of absolute pixel values used in the application (only 421 needed if the application has set <code>android:anyDensity="false"</code> in its 422 manifest)</li> 423 </ul> 424 425 <p>The example screens below illustrate the density independence provided by the 426 platform. Note that both the layouts and launcher icons are displayed at the 427 same physical sizes, although screen sizes, aspect ratios, and densities are 428 different.</p> 429 430 431 <div id=vi09 style=TEXT-ALIGN:left> 432 <img src="{@docRoot}images/screens_support/dip.png" style="padding-bottom:0;margin-bottom:0;" /> 433 <p class="caption" style="margin:0 0 1.5em 1em;padding:0 0 0 434 1em;"><strong>Figure 2.</strong> Examples of density independence on WVGA high 435 density (left), HVGA medium density (center), and QVGA low density (right). </p> 436 </div> 437 438 <p>In most cases, you can take advantage of density independence in your 439 application simply by making sure that your layouts specify all dimension values 440 in density-independent pixels (<code>dip</code> or <code>dp</code>) or 441 scale-independent pixels (<code>sip</code> or <code>sp</code>, for text only). 442 If you are using absolute pixel values in the application and manifest includes 443 <a href="#attrs"><code>android:anyDensity="true"</code></a>, you will also need 444 to scale the pixel values. See <a href="#dips-pels">Converting from dips to 445 pixels</a> for more information. </p> 446 447 448 <h3 id="attrs">Manifest attributes for screens support</h3> 449 450 <p> Android 1.6 introduced a new manifest element, 451 <a href="{@docRoot}guide/topics/manifest/supports-screens-element.html"><code><supports-screens></code></a>, 452 whose attributes you can use to control the 453 display of your application on different classes of device screens, as listed 454 below. The <code>smallScreens</code>, <code>normalScreens</code>, and 455 <code>largeScreens</code> attributes correspond to the generalized screen sizes 456 described in <a href="#range">Range of screens supported</a>, earlier in this 457 document.</p> 458 459 <table id="vrr8"> 460 <tr> 461 <th> 462 Attribute 463 </th> 464 <th > 465 Description 466 </th> 467 <th> 468 Default value,<br><nobr>Android 1.5 and Lower</nobr> 469 </th> 470 <th> 471 Default value,<br><nobr>Android 1.6 and Higher</nobr> 472 </th> 473 </tr> 474 <tr> 475 <td> 476 <code>android:smallScreens</code> 477 </td> 478 <td> 479 Whether or not the application UI is designed for use on 480 <em>small</em> screens — "<code>true</code>" if it is, and 481 "<code>false</code>" if not. </p> 482 </td> 483 <td>"<code>false</code>"</td> 484 <td>"<code>true</code>"</td> 485 </tr> 486 <tr> 487 <td> 488 <code>android:normalScreens</code> 489 </td> 490 <td> 491 Whether or not the application UI is designed for use on 492 <em>normal</em> screens — "<code>true</code>" if it is, and 493 "<code>false</code>" if not. The default value is always "<code>true</code>". 494 </td> 495 <td>"<code>true</code>"</td> 496 <td>"<code>true</code>"</td> 497 </tr> 498 <tr> 499 <td> 500 <code>android:largeScreens</code> 501 </td> 502 <td> 503 Whether or not the application UI is designed for use on 504 <em>large</em> screens — "<code>true</code>" if it is, and 505 "<code>false</code>" if not. 506 </td> 507 <td>"<code>false</code>"</td> 508 <td>"<code>true</code>"</td> 509 </tr> 510 <tr> 511 <td> 512 <code>android:anyDensity</code> 513 </td> 514 <td> 515 <p>Whether or not the application is designed to manage its UI properly 516 in different density environments — "<code>true</code>" if so, and 517 "<code>false</code>" if not. </p> 518 <ul> 519 <li>If set to "<code>true</code>", the platform disables its 520 density-compatibility features for all screen densities — specifically, 521 the auto-scaling of absolute pixel units (<code>px</code>) and math — and 522 relies on the application to use density-independent pixel units 523 (<code>dp</code>) and/or math to manage the adaptation of pixel values according 524 to density of the current screen. That is, as long as your application uses 525 density-independent units (dp) for screen layout sizes, then it will perform 526 properly on different densities when this attribute is set to 527 "<code>true</code>".</li> 528 529 <li>If set to "<code>false</code>", the platform enables its 530 density-compatibility features for all screen densities. In this case, the 531 platform provides a scaled, virtual screen pixel map to the application, against 532 which it can layout and draw its UI as though against a medium-density screen 533 (160). The platform then transparently auto-scales the application's pixel units 534 and math as needed to match the actual device screen density. </li> 535 </ul> 536 <p>Note that the setting of this attribute affects density-compatibility only. 537 It does not affect size-compatibility features such as display on a virtual 538 baseline screen.</p> 539 </td> 540 <td>"<code>false</code>"</td> 541 <td>"<code>true</code>"</td> 542 </tr> 543 </table> 544 545 <p>In general, when you declare a screen-size attribute 546 (<code>smallScreens</code>, <code>normalScreens</code>, or 547 <code>largeScreens</code>) as "<code>true</code>", you are signaling to the 548 platform that your application is designed to render properly on that screen 549 size. As a result, the platform does not apply any size-compatibility features 550 (such as a virtual HVGA display area). If you declare a screen-size attribute as 551 "<code>false</code>", you are signaling that your application is <em>not</em> 552 designed for that screen size. In this case, the platform <em>does</em> apply 553 size-compatibility features, rendering the application in an HVGA baseline 554 display area. If the current screen is larger than <em>normal</em> size, the 555 platform renders the application in a virtual HVGA screen on the larger screen. 556 See <a href="#compatibility-examples">Screen-Compatibility Examples</a> for an 557 illustration of what an application looks like when displayed in a virtual HVGA 558 screen.</p> 559 560 <p>In other words, setting a <code><supports-screens></code> attribute to 561 "<code>false</code>" tells the platform to enable it's compatibility features 562 when displaying the application on a screen of that size <em>or any larger 563 size</em>, if also disallowed. Otherwise, the platform gives the application a 564 normal display area that can use the full device screen area, if 565 appropriate.</p> 566 567 <p>Android Market also makes use of the <code><supports-screens></code> 568 attributes. It uses them to filter the application from devices whose screens 569 are not supported by the application. Specifically, Android Market considers an 570 application compatible with a device if the application supports a screen that 571 is the same or smaller than the current device screen. Android Market filters 572 the application if it disallows the device's screen size and does not support a 573 smaller size. In general, Android does not provide downward size-compatibility 574 features for applications.</p> 575 576 <p>Here are some examples:</p> 577 578 <ul> 579 <li>Assume that you declare <code>smallScreens="false" normalScreens="true" 580 largeScreens="false" </code> in your application's manifest. <p>Although the 581 application is not designed for display on large screens, the platform can still 582 run it successfully in <a href="#compatibility-examples">size-compatibility 583 mode</a>. Android Market does not filter the application from devices 584 <em>normal</em> and <em>large</em> size screens, but does filter it from 585 <em>small</em> size screens, since the application provides no screen support at 586 <em>small</em> size (and there is no smaller size).</p></li> 587 588 <li>Assume that you declare <code>smallScreens="false" normalScreens="false" 589 largeScreens="true"</code> in your application's manifest. <p>Android Market 590 filters the application from users of devices with <em>small</em> and 591 <em>normal</em> size screens. In effect, this prevents such users from 592 installing the application.</p></li> 593 </ul> 594 595 <p>If you declare the <code>android:anyDensity</code> attribute as 596 "<code>true</code>", you are signaling to the platform that your application is 597 designed to display properly on any screen density. In this case, the 598 application must ensure that it declares its UI dimensions using 599 density-independent pixels (<code>dp</code>) and scales any absolute pixel 600 values (<code>px</code>) or math by the scaling factor available from {@link 601 android.util.DisplayMetrics#density android.util.DisplayMetrics.density}. See <a 602 href="#dips-pels">Converting from dips to pixels</a> for an example.</p> 603 604 <p>Note that the setting of the <code>android:anyDensity</code> attribute does 605 not affect the platform's pre-scaling of drawable resources, such as bitmaps and 606 nine-patch images, which always takes place by default. </p> 607 608 <p>The following example shows a manifest that declares support for large, 609 normal, and small screens in any densities.</p> 610 611 <pre><manifest xmlns:android="http://schemas.android.com/apk/res/android"> 612 ... 613 <supports-screens 614 android:largeScreens="true" 615 android:normalScreens="true" 616 android:smallScreens="true" 617 android:anyDensity="true" /> 618 ... 619 </manifest> 620 </pre> 621 <!-- android:resizeable="true" --> 622 <h4 id="defaults"> 623 Default values for attributes 624 </h4> 625 626 <p>The default values for the <code><supports-screens></code> attributes 627 differ, depending on the the value of the 628 <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html"><code>android:minSdkVersion</code></a> 629 attribute in the application's manifest, as well as on 630 the value of <code>android:targetSdkVersion</code>, if declared:</p> 631 632 <div> 633 <ul> 634 <li> 635 If <code>android:minSdkVersion</code> or 636 <code>android:targetSdkVersion</code> is "4" (Android 1.6) or higher, the 637 default value for everything is "<code>true</code>". If your application uses 638 APIs introduced in Android 1.6 or higher, but does not support specific screen 639 densities and/or screen sizes, you need to explicitly set the appropriate 640 attributes to "<code>false</code>". 641 </li> 642 <li> 643 If <code>android:minSdkVersion</code> is declared with a value of "3" 644 (Android 1.5) or lower <em>and</em> a <code>android:targetSdkVersion</code> 645 attribute is <em>not</em> declared with a value of "4" or higher, the default 646 value for all attributes except <code>android:normalScreens</code> is 647 "<code>false</code>". If you are primarily targeting pre-Android 1.6 platforms 648 but also want to support other densities/screen sizes, you need to explicitly 649 set the appropriate attributes to "<code>true</code>". 650 </li> 651 <li> 652 Note that <code>android:normalScreens</code> always defaults to 653 <code>true</code>. 654 </li> 655 </ul> 656 </div> 657 658 659 <h3 id="qualifiers">Resource directory qualifiers for screen size and density</h3> 660 661 <p>Android supports resource directory qualifiers for controlling the selection 662 of resources based on the characteristics of the screen on which your application 663 is running. You can use these qualifiers to provide size- and density-specific 664 resources in your application. For more information about the generalized sizes 665 and densities that correspond to the qualifiers, see <a href="#range">Range 666 of Screens Supported</a>, earlier in this document.</p> 667 668 <table> 669 <tr> 670 <th>Screen characteristic</th> 671 <th>Qualifier</th> 672 <th>Description</th> 673 </tr> 674 675 <tr> 676 <td rowspan="3">Size</td> 677 <td><code>small</code></td> 678 <td>Resources designed for <em>small</em> size screens.</td> 679 </tr> 680 <tr> 681 <td><code>normal</code></td> 682 <td>Resources designed for <em>normal</em> size screens.</td> 683 </tr> 684 <tr> 685 <td><code>large</code></td> 686 <td>Resources for <em>large</em> size screens.</td> 687 </tr> 688 689 <tr> 690 <td rowspan="4">Density</td> 691 <td><code>ldpi</code></td> 692 <td>Resources designed for low-density (<em>ldpi</em>) screens.</td> 693 </tr> 694 <tr> 695 <td><code>mdpi</code></td> 696 <td>Resources designed for medium-density (<em>mdpi</em>) screens.</td> 697 </tr> 698 <tr> 699 <td><code>hdpi</code></td> 700 <td>Resources designed for high-density (<em>hdpi</em>) screens.</td> 701 </tr> 702 <tr> 703 <td><code>nodpi</code></td> 704 <td>Density-independent resources. The platform does not auto-scale resources 705 tagged with this qualifier, regardless of the current screen's density.</td> 706 </tr> 707 708 <tr> 709 <td rowspan="2">Aspect ratio</td> 710 <td><code>long</code></td> 711 <td>Resources for screens of any size or density that have a significantly 712 taller (in portrait mode) and wider (in landscape mode) aspect ratio than the 713 baseline screen configuration.</td> 714 </tr> 715 <tr> 716 <td><code>notlong</code></td> 717 <td>Resources for use only on screens that have an aspect ratio that is similar 718 to the baseline screen configuration.</td> 719 </tr> 720 <tr> 721 <td>Platform version</td> 722 <td><nobr><code>v<api-level></code></nobr></td> 723 <td>Resources that are for use only on a specific API Level or higher. For 724 example, if your application is designed to run on both Android 1.5 (API Level 725 3) and Android 1.6 (API Level 4 and higher), you can use the <code>-v4</code> 726 qualifier to tag any resources that should be excluded when your application is 727 running on Android 1.5 (API Level 3). </td> 728 </tr> 729 </table> 730 731 <p> 732 Note that the density and the screen size are independent parameters and are 733 interpreted by the system individually. For example, WVGA high density is 734 considered a normal screen because its physical size is about the same as one of 735 T-Mobile G1. On the other hand, a WVGA medium density screen is considered a 736 <i>large</i> screen — it offers the same resolution but at lower pixel 737 density, meaning that it is both physically larger than the baseline screen and 738 can display significantly more information than a normal screen size. 739 </p> 740 741 <p>Here is an example of the resource directory structure of an application that 742 supports low and high density, and employs different layout schemes.</p> 743 744 <pre>res/layout/my_layout.xml // layout for normal screen size 745 res/layout-small/my_layout.xml // layout for small screen size 746 res/layout-large/my_layout.xml // layout for large screen size 747 res/layout-large-land/my_layout.xml // layout for large screen size in landscape mode 748 749 res/drawable-ldpi/my_icon.png // icon image for low density 750 res/drawable-mdpi/dpi/my_icon.png // icon for medium density 751 res/drawable-hdpi/my_icon.png // icon image for high density 752 753 res/drawable-nodpi/composite.xml // density independent resource 754 </pre> 755 756 <p>For more information about how to use resource qualifiers or how the platform 757 selects them, please read 758 <a href="{@docRoot}guide/topics/resources/providing-resources.html#AlternativeResources"> 759 Alternative Resources</a>.</p> 760 761 762 <h2 id="screen-independence">Best practices for Screen Independence</h2> 763 764 <p>The objective of supporting multiple screens is to create an application that 765 can run properly on any display and function properly on any of the generalized 766 screen configurations supported by the platform. 767 </p> 768 769 <p>You can easily ensure that your application will display properly on 770 different screens. Here is a quick checklist:</p> 771 772 <ol> 773 <li> 774 Prefer wrap_content, fill_parent and the dip unit to px in XML layout files 775 </li> 776 <li> 777 Avoid AbsoluteLayout 778 </li> 779 <li> 780 Do not use hard coded pixel values in your code 781 </li> 782 <li> 783 Use density and/or resolution specific resources 784 </li> 785 </ol> 786 787 <h3 id="use-relative">1. Prefer wrap_content, fill_parent and the dip unit to 788 absolute pixels<br> </h3> 789 790 <p>When defining the <code>layout_width</code> and <code>layout_height</code> of 791 views in an XML layout file, using <code>wrap_content</code>, 792 <code>fill_parent</code> or the <code>dip</code> will guarantee that the view is 793 given an appropriate size on the current device screen. For instance, a view 794 with a <code>layout_width="100dip"</code> will measure 100 pixels wide on an 795 HVGA@160 density display and 150 pixels on a WVGA@240 density display, but the 796 view will occupy approximately the same physical space. </p> 797 798 <p>Similarly, you should prefer the <code>sp</code> (scale-independent pixel, 799 the scale factor depends on a user setting) or <code>dip</code> (if you don't 800 want to allow the user to scale the text) to define font sizes.</p> 801 802 <h3 id="avoid-absolute">2. Avoid AbsoluteLayout </h3> 803 804 <p>{@link android.widget.AbsoluteLayout AbsoluteLayout} 805 is one of the layout containers offered by the Android UI toolkit. Unlike the 806 other layouts however, <code>AbsoluteLayout</code> enforces the use of fixed 807 positions which might easily lead to user interfaces that do not work well on 808 different displays. Because of this, <code>AbsoluteLayout</code> was deprecated 809 in Android 1.5 (API Level 3). </p> 810 811 <p>You can achieve much the same layout by using a 812 {@link android.widget.FrameLayout FrameLayout} instead, and setting 813 <code>layout_margin</code> attributes of the children. This approach is more 814 flexible and will yield better results on different screens.</p> 815 816 <h3>3. Do not use hard-coded pixel values in your code</h3> 817 818 <p>For performance reasons and to keep the code simpler, the Android framework 819 API uses pixels as the standard unit for expressing dimension or coordinate 820 values. That means that the dimensions of a View are always expressed in the 821 code in pixels. For instance, if <code>myView.getWidth()</code> returns 10, the 822 view is 10 pixels wide. In some cases, you may need to scale the pixel values 823 that you use in your code. The sections below provide more information. </p> 824 825 <h4 id="dips-pels">Converting from dips to pixels</h4> 826 827 <p>In some cases, you will need to express dimensions in <code>dip</code> and 828 then convert them to pixels. Imagine an application in which a scroll gesture is 829 recognized after the user's finger has moved by at least 16 pixels. On a 830 baseline screen, the user will have to move his finger by 16 pixels / 160 831 dpi = 1/10th of an inch (or 2.5 mm) before the gesture is recognized. On a 832 device with a high (240) density display, the user will move his finger by only 833 16 pixels / 240 dpi = 1/15th of an inch (or 1.7 mm.) The distance is much 834 shorter and the application thus appears more sensitive to the user. To fix this 835 issue, the gesture threshold must be expressed in the code in <code>dip</code> 836 and then converted to actual pixels.</p> 837 838 <pre>// The gesture threshold expressed in dip 839 private static final float GESTURE_THRESHOLD_DIP = 16.0f; 840 841 // Convert the dips to pixels 842 final float scale = getContext().getResources().getDisplayMetrics().density; 843 mGestureThreshold = (int) (GESTURE_THRESHOLD_DIP * scale + 0.5f);</span> 844 845 // Use mGestureThreshold as a distance in pixels 846 </pre> 847 848 <p>The {@link android.util.DisplayMetrics#density android.util.DisplayMetrics.density} 849 field specifies the the scale factor you must use to 850 convert dips to pixels according to the current screen density. You can access 851 the current screen's metrics through a <code>Context</code> or 852 <code>Activity</code>. On a medium (160) density screen, 853 <code>DisplayMetrics.density</code> equals "1.0", whereas on a high (240) 854 density screen it equals "1.5". You can refer to the documentation of the 855 {@link android.util.DisplayMetrics DisplayMetrics} 856 class for details.</p> 857 858 <h4>Use pre-scaled configuration values</h4> 859 860 <p>The {@link android.view.ViewConfiguration ViewConfiguration} class can be 861 used to access the most common distances, speeds, and times used in the Android 862 framework. For instance, the distance in pixels used by the framework as the 863 scroll threshold can be obtained as follows:</p> 864 865 <pre>ViewConfiguration.get(aContext).getScaledTouchSlop()</pre> 866 867 <p>Methods starting with the <code>getScaled</code> prefix are guaranteed to return a value in pixels that will display properly regardless of the current screen density.</p> 868 869 <h3>4. Use density and/or size-specific resources</h3> 870 871 <div style="float: right;background-color:#fff;margin: 0;padding: 20px 0 20px 20px;"> 872 <img src="{@docRoot}images/screens_support/scale-test.png" style="padding:0;margin:0;"> 873 <p class="caption" style="margin:0;padding:0;"><strong>Figure 3.</strong> Comparison of pre-scaled and auto-scaled bitmaps.</p> 874 </div> 875 876 <p>Even with the size- and density-compatibility features that the platform 877 provides, you may still want to make adjustments to the UI of your application 878 when it displayed on certain screen sizes or densities. You can do this by 879 providing size- or density-specific resources — assets, layouts, strings, 880 and so on. If you want, you can also take control over the scaling of images 881 assets. The sections below provide more information.</p> 882 883 <h4 id="resource-dirs">Custom resources and directories</h4> 884 885 <p>If you need to control exactly how your application will look on various 886 displays, simply adjust your assets and layouts in configuration-specific 887 resources directories. For example, consider an icon that you want to display on 888 medium and high density screens. Simply create your icon at two different sizes 889 (for instance 100x100 for medium density and 150x150 for high density) and put 890 the two variations in the appropriate directories, using the proper 891 qualifiers:</p> 892 893 <p style="margin-left:2em;"><code>res/drawable-mdpi/icon.png // 894 for medium-density screens</code></p> 895 896 <p style="margin-left:2em;"><code>res/drawable-hdpi/icon.png // 897 for high-density screens</code></p> 898 899 <p>If a density qualifier is not defined in a resource directory name, the 900 platform assumes that the resources in that directory are designed for the 901 baseline medium density. It is not recommended that you put density-specific 902 resources such as images in the default directory.</p> 903 904 <p>For more information about valid resource qualifiers, see 905 <a href="#qualifiers">Resource directory qualifiers</a>, earlier in this 906 document.</p> 907 908 <h4 id="scaling">Pre-scaling and auto-scaling of bitmaps and nine-patches</h4> 909 910 <p>When a bitmap or nine-patch image is loaded from the application's resources, 911 the platform attempts to pre-scale it to match the display's density. For 912 instance, if you placed a 100x100 icon in the <code>res/drawable/</code> 913 directory and loaded that icon as a bitmap on a high-density screen, Android 914 would automatically scale up the icon and produce a 150x150 bitmap.</p> 915 916 <p>This pre-scaling mechanism works independently of the source. For instance, 917 an application targeted for a high-density screen may have bitmaps only in the 918 <code>res/drawable-hdpi/</code> directory. If one of the bitmaps is a 240x240 919 icon and is loaded on a medium-density screen, the resulting bitmap will measure 920 160x160.</p> 921 922 <p>The platform pre-scales resources as needed, whether the application is 923 running with density-compatibility features enabled or not (as specified by the 924 value of <code>android:anyDensity</code>). However, when running with 925 density-compatibility enabled, the platform continues to report the size of 926 pre-scaled bitmaps and other resources as if they were loaded in a 927 medium-density environment. For example, when density-compatibility is enabled, 928 if you load a 76x76 image from the default resources for display on a 929 high-density screen, the platform will pre-scale the image to 114x114 930 internally. However, the API still reports the size of the image as 76x76. This 931 discrepancy may cause unexpected behavior if your application somehow directly 932 manipulates the scaled bitmap, but this was considered a reasonable trade-off to 933 keep the performance of existing applications as good as possible.</p> 934 935 <p>This does not apply for the case that an application creates an in-memory 936 bitmap internally and draws something on it, for later display on the screen. 937 The platform auto-scales such bitmaps on the fly, at draw time. Other side 938 effects of such a case might be that fonts drawn in such a bitmap will be scaled 939 at the bitmap level, when the off-screen bitmap is finally rendered to the 940 display, resulting in scaling artifacts.</p> 941 942 <p>There are situations in which you may not want Android to automatically scale 943 a resource. The easiest way to accomplish this is to put it in a "nodpi" 944 resource directory:</p> 945 946 <p style="margin-left:2em;"><code>res/drawable-nodpi/icon.png</code></p> 947 948 <p>You can also take complete control of the scaling mechanism by using the 949 {@link android.graphics.BitmapFactory.Options BitmapFactory.Options} class, 950 which lets you define whether you want the bitmap to be pre-scaled and what the 951 density of the bitmap should be. For instance, if you are loading a bitmap from 952 a web server, you may want to force the bitmap's density to be high density. 953 When pre-scaling is disabled, the resulting bitmap is in auto-scaling mode. The 954 bitmap is associated with a density (that you may or may not have specified 955 through the <code>BitmapFactory.Options</code>) which will be used to scale the 956 bitmap on screen <em>at drawing time</em>. 957 958 <p>Using auto-scaling instead of pre-scaling is more CPU expensive than 959 pre-scaling but uses less memory. You can refer to the documentation of 960 {@link android.graphics.BitmapFactory BitmapFactory}, 961 {@link android.graphics.Bitmap Bitmap}, and 962 {@link android.graphics.Canvas Canvas} for more 963 information on auto-scaling.</p> 964 965 <p>Figure 3, at right, demonstrates the results of the pre-scale and auto-scale 966 mechanisms when loading low (120), medium (160) and high (240) density bitmaps 967 on a baseline screen. The differences are subtle, because all of the bitmaps are 968 being scaled to match the current screen density, however the scaled bitmaps 969 have slightly different appearances depending on whether they are pre-scaled or 970 auto-scaled at draw time.</p> 971 972 <h2 id="strategies">Strategies for Legacy Applications</h2> 973 974 <p>If you have already developed and published an Android application based on 975 Android 1.5 or earlier platform version, you need to consider how you will adapt 976 your application so that it is deployable to </p> 977 978 <ul> 979 <li>Existing devices, which may be running Android 1.5 (or lower) platform 980 version, as well as to </li> 981 <li>Newer devices that are running Android 1.6 (or higher) and offering various 982 screen sizes and resolutions</li> 983 </ul> 984 985 <p>To support the newer devices and the different screens they use, you might 986 need to make some changes in your app, but at the same time your app may be very 987 stable and so you want to minimize the changes. There are a variety of ways that 988 you can extend your existing application to support new devices with multiple 989 screens <em>and</em> existing devices running older platform versions. You 990 should be able to make these changes to your application such that you can 991 distribute a single .apk to any and all devices.</p> 992 993 <p>The recommended strategy is to develop against the most recent version of the 994 platform you are targeting, and test on the minimum one you want to run on. 995 Here's how to do that:</p> 996 997 <ol> 998 <li>Maintain compatibility with existing devices by leaving your application's 999 <code>android:minSdkVersion</code> attribute as it is. You <em>do not</em> need 1000 to increment the value of the attribute to support new devices and multiple 1001 screens. </li> 1002 <li>Extend compatibility for Android 1.6 (and higher) devices by adding 1003 a new attribute — <code>android:targetSdkVersion</code> — to the 1004 <code>uses-sdk</code> element. Set the value of the attribute to 1005 "<code>4</code>". This allows your application to "inherit" the platform's 1006 multiple screens support, even though it is technically using an earlier version 1007 of the API. </li> 1008 <li>Add an empty <code><supports-screens></code> element as a child of 1009 <code><manifest></code>. If you need to enable size or density attributes 1010 later, this is where you will add them.</li> 1011 <li>Change your application's build properties, such that it compiles against 1012 the Android 1.6 (API Level 4) library, rather than against the Android 1.5 (or 1013 earlier) library. You will not be able to compile your application against the 1014 older platform because of the new manifest attribute. </li> 1015 <li>Set up AVDs for testing your application on Android 1.6 and higher 1016 releases. Create AVDs that use the screen sizes and densities that you want to 1017 support. When you create the AVDs, make sure to select the Android 1.6 or higher 1018 platform as the system image to run. For more information, see <a 1019 href="#testing">How to Test Your Application on Multiple Screens</a>, 1020 below.</li> 1021 <li>Set up AVDs for testing your application on Android 1.5 (or earlier 1022 platform). You need AVDs running the older platforms you are targeting, so that 1023 you can test for compatibility and ensure that there are no functional 1024 regressions. </li> 1025 <li>Compile your application against the Android 1.6 library and run it on the 1026 AVDs you created. Observe the way your application looks and runs, and test all 1027 of the user interactions. </li> 1028 <li>Debug any display or functional issues. For issues that you resolve in 1029 your application code, <span style="color:red">make certain not to use any APIs 1030 introduced in API Level 4 or later</span>. If you are in doubt, refer to SDK 1031 reference documentation and look for the API Level specifier for the API you 1032 want to use. Using an API introduced in API Level 4 or later will mean that your 1033 application will no longer be compatible with devices running Android 1.5 or 1034 earlier.</li> 1035 <li>For resource-related issues, you can try resolving them by: 1036 <ul> 1037 <li>Adding a <code>anyDensity="false"</code> attribute to 1038 <code><supports-screens></code>, to enable density-compatibility 1039 scaling.</li> 1040 <li>Creating any size- or density-specific resources you need and placing 1041 them in directories tagged with the <a href="#qualifiers">correct 1042 qualifiers</a>. Qualifiers must be arranged in a proscribed order. See 1043 <a href="{@docRoot}guide/topics/resources/providing-resources.html#AlternativeResources"> 1044 Alternative Resources</a> for more information. </li> 1045 <li>Note that if you add size- or density-specific resource directories 1046 tagged with any of the resource qualifiers listed in this document, you should 1047 make sure to also tag those directories with the <code>v<api-level></code> 1048 qualifier (for example, <code>-v4</code>). This ensures that those resources 1049 will be ignored when the application is run on Android 1.5 or lower platform 1050 versions.</p></li> 1051 </ul> 1052 </li> 1053 <li>If your application does not offer support (such as custom layouts) for 1054 large screens and you want the platform to display your application in 1055 screen-compatibility mode on larger screens, add a 1056 <code>largeScreens="false"</code> attribute to the 1057 <code><supports-screens></code> element in the manifest. See 1058 <a href="#compatibility-examples">Screen-Compatibility Examples</a> for 1059 illustrations of how the platform displays your application in this case.</li> 1060 <li>If your application does not offer support (such as custom layouts) for 1061 small screens (such as on a QVGA low-density screen) and you do not want Android 1062 Market to offer the application to users of small-screen devices, you 1063 <em>must</em> add a <code>smallScreens="false"</code> attribute to the 1064 <code><supports-screens></code> element. </li> 1065 <li>Continue testing and debugging until your application performs as expected 1066 on all of the platforms and screen sizes your application will support.</li> 1067 <li>Export, zipalign, and sign your application using the same private key you 1068 used when publishing the previous version, then publish the application to users 1069 as an update. </li> 1070 </ol> 1071 1072 <p>In particular, remember to test your application on an AVD that emulates a 1073 small-screen device. Devices that offer screens with QVGA resolution at low 1074 density are available now. Users of those devices may want to download your 1075 application, so you should understand how your application will look and 1076 function on a small-screen device. In many cases, the reduced screen area and 1077 density mean that you may need to make tradeoffs in design, content, and 1078 function on those devices. </p> 1079 1080 <h2 id="testing">How to Test Your Application on Multiple Screens</h2> 1081 1082 <p>Before publishing an application that supports multiple screens, you should 1083 thoroughly test it in all of the targeted screen sizes and densities. You can 1084 test how it displays with the platform's compatibility features enabled or with 1085 screen-specific UI resources included in your application. The Android SDK 1086 includes all the tools you need to test your application on any supported 1087 screen.</p> 1088 1089 <!-- You can test in any minsdk, and you can test with compatabiltiy code or 1090 not. Once you've tested your application and found that it displays properly on 1091 various screen sizes, you should make sure to add the corresponding size 1092 attribute(s) to your application's manifest. --> 1093 1094 <div id="f9.5" style="float:right;margin:0;padding:0;"> 1095 <img src="{@docRoot}images/screens_support/avds-config.png" style="padding:0;margin:0;"> 1096 <p class="caption" style="margin:0 0 1.5em 1em;padding:0 0 0 1em;"><strong>Figure 4.</strong> 1097 A typical set of AVDs for testing screens support.</p> 1098 </div> 1099 1100 <p>As a test environment for your applications, set up a series of AVDs that 1101 emulate the screen sizes and densities you want to support. The Android SDK 1102 includes six emulator skins to get you started. You can use the Android AVD 1103 Manager or the <code>android</code> tool to create AVDs that use the various 1104 emulator skins and you can also set up custom AVDs to test densities other than 1105 the defaults. For general information about working with AVDs, see 1106 <a href="{@docRoot}guide/developing/tools/avd.html">Android Virtual 1107 Devices</a>.</p> 1108 1109 <p>The Android SDK provides a set of default emulator skins that you can use for 1110 testing. The skins are included as part of each Android platform that you can 1111 install in your SDK. The Android 1.6 platform offers these default skins:</p> 1112 1113 <ul> 1114 <li> 1115 QVGA (240x320, low density, small screen) 1116 </li> 1117 <li> 1118 HVGA (320x480, medium density, normal screen) 1119 </li> 1120 <li> 1121 WVGA800 (480x800, high density, normal screen) 1122 </li> 1123 <li> 1124 WVGA854 (480x854 high density, normal screen) 1125 </li> 1126 </ul> 1127 1128 <p>The Android 2.0 platform offers all of the Android 1.6 default skins, 1129 above, plus:</p> 1130 1131 <ul> 1132 <li> 1133 WQVGA400 (240x400, low density, normal screen) 1134 </li> 1135 <li> 1136 WQVGA432 (240x432, low density, normal screen) 1137 </li> 1138 </ul> 1139 1140 <p>If you are using the <code>android</code> tool command line to create your 1141 AVDs, here's an example of how to specify the skin you want to use:</p> 1142 1143 <pre>android create avd ... --skin WVGA800</pre> 1144 1145 <p>We also recommend that you test your application in an emulator that is set 1146 up to run at a physical size that closely matches an actual device. This makes 1147 it a lot easier to compare the results at various resolutions and densities. To 1148 do so you will need to know the approximate density, in dpi, of your computer 1149 monitor (a 30" Dell monitor has for instance a density of about 96 dpi.). Use 1150 your monitor's dpi as the value of the <code>-scale</code> option, when 1151 launching the emulator, for example:</p> 1152 1153 <pre>emulator -avd <name> -scale 96dpi</pre> 1154 1155 <p>If you are working in Eclipse with ADT, you can specify the <code>-scale 1156 96dpi</code> option in the Target tab of run and debug configurations, under 1157 "Additional Emulator Command Line Options" field. </p> 1158 1159 <p>Note that starting the emulator with the <code>-scale</code> option will 1160 scale the entire emulator display, based on both the dpi of the skin and of your 1161 monitor. The default emulator skins included in the Android SDK are listed 1162 in <a href="#screens-table">Table 1</a>, earlier in this document.</p> 1163 1164 <div style="float: right;background-color:#fff;margin: 0;padding: 20px 0 20px 20px;width:520px;"> 1165 <img src="{@docRoot}images/screens_support/avd-density.png" style="padding:0;margin:0;"> 1166 <p class="caption" style="margin:0 0 1.5em 1em;padding:0 0 0 1em; width:280px;"><strong>Figure 5.</strong> 1167 Resolution and density options that you can use, when creating an AVD using the AVD Manager.</p> 1168 </div> 1169 1170 <p>You should also make sure to test your application on different physical 1171 screen sizes within a single size-density configuration. For example, to 1172 display this screen configuration on a 30" monitor you will need to adjust 1173 the value passed to <code>-scale</code> to 96*2.8/3.3 = 81dpi. You can also 1174 pass a float value to <code>-scale</code> to specify your own scaling factor:</p> 1175 1176 <pre>emulator -avd <name> -scale 0.6</pre> 1177 1178 <p>If you would like to test your application on a screen that uses a resolution 1179 or density not supported by the built-in skins, you can either adjust an 1180 existing skin, or create an AVD that uses a custom resolution or density.</p> 1181 1182 <p>In the AVD Manager, you can specify a custom skin resolution or density in 1183 the Create New AVD dialog, as shown in Figure 5, at right.</p> 1184 1185 <p>In the <code>android</code> tool, follow these steps to create an AVD with a 1186 custom resolution or density:</p> 1187 1188 <ol> 1189 <li>Use the <code>create avd</code> command to create a new AVD, specifying 1190 the <code>--skin</code> option with a value that references either a default 1191 skin name (such as "WVGA800") or a custom skin resolution (such as 240x432). 1192 Here's an example: 1193 <pre>android create avd -n <name> -t <targetID> --skin WVGA800</pre> 1194 </li> 1195 <li>To specify a custom density for the skin, answer "yes" when asked whether 1196 you want to create a custom hardware profile for the new AVD.</li> 1197 <li>Continue through the various profile settings until the tool asks you to 1198 specify "Abstracted LCD density" (<em>hw.lcd.density</em>). Enter an appropriate 1199 value, such as "120" for a low-density screen, "160" for a medium density screen, 1200 or "240" for a high-density screen.</li> 1201 <li>Set any other hardware options and complete the AVD creation.</li> 1202 </ol> 1203 1204 <p>In the example above (WVGA medium density), the new AVD will emulate a 5.8" 1205 WVGA screen.</p> 1206 1207 <p>As an alternative to adjusting the emulator skin configuration, you can use 1208 the emulator skin's default density and add the <code>-dpi-device</code> option 1209 to the emulator command line when starting the AVD. For example, </p> 1210 1211 <pre>emulator -avd WVGA800 -scale 96dpi -dpi-device 160</pre> 1212 1213 1214 <h2 id="compatibility-examples">Screen-Compatibility Examples</h2> 1215 1216 <p>This section provides examples of how the Android platform displays an 1217 application written for the baseline screen configuration — HVGA (320x480) 1218 resolution on a 3.2" screen — with all of the platform's size- and 1219 density-compatibility features enabled. That is, the examples show how 1220 the platform displays an application that doesn't provide built-in support 1221 for the screen on which it is being rendered, but which instead relies completely 1222 on the platform.</p> 1223 1224 <p>The platform's screen-compatibility features are designed to provide such 1225 an application with a virtual baseline screen environment against which to run, 1226 while at the same time ensuring for the user a physical display that is 1227 approximately the same as the baseline screen size and density. </p> 1228 1229 <p>Legacy applications that have not been modified to support multiple 1230 screens would be typical examples of such applications. In most cases, 1231 you would want to add multiple-screens support to a legacy application and 1232 publish an updated version, as described in <a href="#strategies">Strategies 1233 for Legacy Applications</a>. However, if you did not do so, the 1234 platform still performs best-effort rendering of your application, as 1235 illustrated below.</p> 1236 1237 <p> Internally, these are the compatibility features that the platform 1238 provides, based on the current device screen:</p> 1239 1240 <ul> 1241 <li> 1242 If the device's screen density is <em>not medium</em>, the application's 1243 layout and drawing of its content is as if the screen <em>is</em> medium density, but the 1244 framework scales the layout and images (if the image for the target density is 1245 not available) to fit the target density. It scales 1.5 times if the target 1246 density is high density (160->240 virtual dpi), or 0.75 times if the target 1247 density is low density (160 -> 120 virtual dpi). 1248 </li> 1249 <li> 1250 If the device's screen size is <em>small</em>, there are few options 1251 options for making Android 1.5 applications work well on such a screen, so 1252 Android Market will filter applications that are not known to support these 1253 screens from the device. 1254 </li> 1255 <li> 1256 If the device's screen size is <em>large</em>, it limits the application's 1257 screen to the normal size and draws a black background around the application. 1258 For example, if an application supports high density, but does not support large 1259 screens, it only uses a 480x720 area of the screen and the rest will be filled 1260 with a black background (see example below). 1261 </li> 1262 </ul> 1263 1264 <table style="width:10%;margin-left:.5em;"> 1265 <tr> 1266 <td> 1267 HVGA, normal size, normal density<br> 1268 [ emulator -skin HVGA ]<br> 1269 <img height=149 src="{@docRoot}images/screens_support/afdvfckr9j_15dcsvrscg_b.png" width=225> 1270 </td> 1271 <td> 1272 WVGA, normal size, high density<br> 1273 [emulator -skin WVGA854 -dpi-device 240]<br> 1274 <img height=143 src="{@docRoot}images/screens_support/afdvfckr9j_18c6mhm3cm_b.png" width=254><br> 1275 <p>The application occupies full screen as its considered to be normal size. (close to 480x720)</p> 1276 </td> 1277 </tr> 1278 <tr> 1279 <td> 1280 VGA, large size, medium density<br> 1281 [ emulator -skin 640x480 ]<br> 1282 <img height=243 src="{@docRoot}images/screens_support/afdvfckr9j_14fj6dhsc3_b.png" width=324> 1283 <p>The application occupies 320x480 of VGA.</p> 1284 </td> 1285 <td> 1286 SVGA, large size, high density<br> 1287 [ emulator -skin 800x600 -dpi-device 240]<br> 1288 <img height=223 src="{@docRoot}images/screens_support/afdvfckr9j_19c743p6cr_b.png" width=294> 1289 <p>The application occupies 480x720 (=1.5 x [320x480]) of 800x600.</p> 1290 </td> 1291 </tr> 1292 </table> 1293 1294 1295 <h3>Screen-compatibility limitations on small, low-density screens</h3> 1296 1297 <p>Because these device has smaller state/resolution, there are known 1298 limitations when application runs in compatibility mode.</p> 1299 1300 <h4>QVGA</h4> 1301 1302 <p>Because QVGA (240x320) screens have less screen area available and lower 1303 density than normal, which is 240x360 in low density, some applications cannot 1304 render all their content properly on those screens. As a result, on a QVGA 1305 device, Android Market will filter out all applications that do not declare they 1306 support small screens.</p> 1307 1308 <p>Examples:</p> 1309 1310 <table style="width:10%;margin-left:.5em;"> 1311 <tr> 1312 <td>The part of z value graph is chopped.</td> 1313 <td>The lap time area is chopped.<br></td> 1314 </tr> 1315 <tr> 1316 <td><img height=207 src="{@docRoot}images/screens_support/afdvfckr9j_16g95wjqg3_b.png" width="155"></td> 1317 <td><img height=186 src="{@docRoot}images/screens_support/afdvfckr9j_17p2w4txgc_b.png" width="139"></td> 1318 </tr> 1319 </table> 1320 1321 1322 <h4>Images with 1 pixel height/width.</h4> 1323 1324 <p>If an image has 1 pixel height or width, it may not be shown on the screen 1325 due to rounding issue. This is inevitable as it just does not have enough 1326 pixels.</p> 1327 1328 <p>For example, in the screen below, the divider in the menu is invisible 1329 because the width of the image is trancated to 0. (This particular problem is 1330 solvable because menu is handled inside framework, but there is no generic 1331 solution as it just does not have enough pixels.)</p> 1332 1333 <img height=222 src="{@docRoot}images/screens_support/afdvfckr9j_20fvptbbdd_b.png" width=166> 1334 1335 1336 1337