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