How Android supports multiple screens

Using the alternative resources framework使用可选资源框架

The platform's support for loading screen size- and density-specific resources at run time is based on the alternative resources framework.

If you want to use size- or density-specific layouts or drawables in your application and you are not familiar with resource qualifiers or how the platform uses them, please read Alternative Resources.

平台支持在运行时加载基于可选资源框架的多屏幕尺寸和特定密度的资源

如果你想要使用尺寸或者特定密度布局或者是可利用的应用程序,如果你不熟悉资源限定符或者是如何在平台上使用它们,请阅读Alternative Resources.

The foundation of Android's support for multiple screens is a set of built-in compatibility features that together manage the rendering of application resources in an appropriate way for the current device screen. The platform handles most of the work of rendering your application, but also gives you two key ways to control how your application is displayed, if you need or want to use them:

Android起初支持多屏幕是在一组嵌入兼容装置同时用合适的方式管理当前装置的屏幕中应用程序资源的呈现

The platform supports a set of resource qualifiers that let you provide size- and density-specific resources, if needed. The qualifiers for size-specific resources are large, normal, and small, and those for density-specific resources are hdpi (high), mdpi (medium), and ldpi (low). The qualifiers correspond to the generalized densities given in Table 1, above.

。该平台支持一组让你提供尺寸和特定密度的资源限定符,如果需要,对特定资源的限定分为largenormalsmall,对特定密度资源的限定分为hdpihigh),mdpi (medium), and ldpi (low),特定密度的限制符在上表1中已给出。

The platform also provides a <supports-screens> manifest element, whose attributes android:largeScreens, android:normalScreens, and android:smallScreens let you specify what generalized screen sizes your application supports. A fourth attribute, android:anyDensity, lets you indicate whether or not your application includes built-in support for multiple densities.

该平台也提供一个manifest元素<supports-screens>,它的属性android:largeScreens, android:normalScreens, android:smallScreens可以让你指定你的应用程序中所支持的屏幕尺寸,第四个属性android:anyDensity可以指明你的程序是否包含对多重密度的嵌入支持。

At run time, the platform provides three types of support to your application, to ensure the best possible display on the current device screen:

当运行的时候,为了确保在当前的设备屏幕上有最佳的呈现,该平台对你的应用程序提供三种类型的支持:

1、 Pre-scaling of resources (such as image assets)

Based on the density of the current screen, the platform automatically loads any size- or density-specific resources from your application and displays them without scaling. If no matching resources are available, the platform loads the default resources and scales them up or down as needed to match the current screen's generalized density. The platform assumes that default resources are designed for proper display at the baseline screen density of "medium" (160), unless they are loaded from a density-specific resource directory.

For example, if the current screen's density is "high", the platform loads resources that are tagged with the qualifier hdpi and uses them without scaling. If no such resources are available, the platform uses the default resources instead, scaling them from the baseline density ("medium") to "high".

For more information about how to create size- and density-specific resources, see Resource qualifiers.

根据当前屏幕的密度,该平台自动从你的应用程序中加载任何尺寸或者特定密度资源,而且不进行缩放的呈现。如果没有可供使用的资源相匹配,该平台会自动将在默认的资源,并且根据所需增大或者缩放它们来匹配当前屏幕资源的广义密度。该平台假设默认资源在medium屏幕密度的底线范围能适当的呈现,除非他们加载一个特定密度的资源目录。

例如,如果当前屏幕的密度为high,该平台加载资源时标记它的限定符为hdpi,并且不用缩放就可以使用它们。如果没有相关的资源,该平台就会用默认的资源代替,从密度的底线medium缩放到high

2Auto-scaling of pixel dimensions and coordinates

If the application states that it does not support different screen densities, the platform auto-scales any absolute pixel coordinates, pixel dimension values, and pixel math used in the application (such as might be used for specifying the width or padding for a view). It does this to ensure that pixel-defined screen elements are displayed at approximately the same physical size as they would be at the baseline density of "medium" (160). The platform handles this scaling transparently to the application and also reports scaled overall pixel dimensions to the application, rather than physical pixel dimensions.

For instance, suppose a given device is using a WVGA high-denisty screen, which is 480x800 and about the same size as a traditional HVGA screen, but it's running an app that states that it does not support multiple densities.

In this case, the system will "lie" to the application when it queries for screen dimensions, and report 320x533.

Then, when the app does drawing operations, such as invalidating the rectangle from (10,10) to (100, 100), the system will likewise automatically transform the coordinates by scaling them the appropriate amount, and actually invalidate the region (15,15) to (150, 150). The same thing happens in the other direction, if the application is running on a lower-density screen, coordinates are scaled down.

For more information, see the android:anyDensity attribute in Manifest attributes for screens support.

如果应用程序的状态显示它并不支持多种屏幕密度,该平台自动在应用程序中缩放任何绝对的像素坐标,像素密度值,以及像素数。(比如可能会指定特定的宽度或者为一个view填充)。这样做是为了,当它们处于medium的底线密度时,确保自定义像素的屏幕元素以近似相同的物理尺寸呈现。该平台会为应用程序处理明显的缩放,而且会把全部的缩放像素规模通知给应用程序,而并不是物理像素尺寸。

例如,假设一个设备使用的是WVGA高密度480*480的屏幕,和相同的尺寸的HVGA屏幕,但是它运行一个app时状态显示它并不支持多重密度。

这种情况下,当它询问页面尺寸时,系统就会对应用程序“撒谎”说报告时320*533

然后,当app做绘图操作时,比如说让矩形从(10,10)到(100,100)变化,同样地,系统将会通过缩放它们到接近的数据来自动改变坐标,实际上,改变反问式从(15,15) (150, 150),其他的方向也会发生相同的事情,如果应用程序运行在一个低密度的屏幕中,坐标会按比例缩放。

Publishing to Small Screen Devices

To ensure the best experience for users on small-screen devices, Android Market only shows applications that explicitly declare support for small screens. If you developed an application on Android 1.5 or earlier and published it on Android Market, you need to test your application on small screens and then upload an updated version that explicitly indicates support for small screens.

为了确保给用户在小屏幕设备中以最佳的体检,android市场唯一展示了改应用程序是明确的支持小屏幕的。如果你在anroid1.5或者是更早的版本上开发,并且把它发布在android market,你需要在小屏幕上测试你的程序,并且在更新的版本上去装载它,以验证它是否支持小屏幕。

3、Compatibility-mode display on larger screen-sizes

If the current screen's size is larger than your application supports, as specified in the supports-screens element, the platform displays the application at the baseline size ("normal") and density ("medium). For screens larger than baseline, the platform displays the application in a baseline-sized portion of the overall screen, against a black background.

如果当前屏幕的大小大于您的应用程序所支持的supports-screens元素中声明的尺寸,该平台会在基线尺寸(normal)和密度(medium)下显示应用程序,对于比基线大的屏幕,平台将会在整个屏幕的部分用基线尺寸来出现,而并不是用黑色背景。

For instance, suppose a given device is using a WVGA medium density screen, classified as a "large" screen, but the application states that it does not support large screens; in this case, the system will again "lie" to the application when it queries for screen dimensions, and report 320x480. Instead of scaling the application, however, the application's 320x480 interface will be placed as a "postage stamp" in the larger 480x800 screen.For more information, see the android:anyDensity attribute in Manifest elements for screens support and the Screen-Compatibility Examples section.

例如,假设一个给定的设备使用的是中密度的WVGA屏幕,作为一个“large”屏幕划分,但应用程序状态显示它不支持large屏幕,在这种情况下,当它查询屏幕尺寸时,系统将再次撒谎,并报告320x480。而不是缩放的应用程序,但是,该应用程序的320*480用户界面将会以“邮票”的方式放置在比较大的480*480的屏幕上。

In general, these compatibility features ensure that all applications, including those written against Android 1.5 and earlier platform versions, can display properly on most devices, especially when the device's screen is at the baseline "normal" size or larger.

一般来说,这些兼容功能确保所有应用程序,包括对android1.5平台或者早期版本,都可以显示在大多数设备,特别是当设备的屏幕在基准是正常尺寸或者是large

However, note that applications written for the baseline screen may need minor adjustments before they display properly on smaller screens such as QVGA. With the reduced screen area of small screens, there may be tradeoffs in design, content, and function that you, as the application developer, need to consider. For more information about how to prepare an existing application for display on small screens, see Strategies for Legacy Applications.

但是请注意,在它在诸如QVGA的小屏幕上合适的显示之前,应用程序对基线屏幕的书写需要一些小调整,随着小屏幕的屏幕面积减少,作为应用程序的开发者,有可能在设计、内容、函数上需要考虑调整,The sections below provide more information how to take advantage of the platform's multiple-screens support.

更多相关文章

  1. android 全屏幕显示以及竖屏显示
  2. android调节屏幕亮度
  3. android4.3应用程序隐藏状态栏和标题栏
  4. Android计量单位px,in,mm,pt,dp,dip,sp和获取屏幕尺寸与密度
  5. android根据屏幕高度改变item占ListView高度
  6. 一、 Android完全退出应用程序
  7. Android--取得控件在手机屏幕上的位置

随机推荐

  1. android 查看图片、保存图片
  2. 苦逼啊--qt for android 5.4.1 camera
  3. android canvas使用line画半园
  4. android下载安装APK
  5. android 监听其它app的错误或者崩溃的方
  6. Android: activity的过渡动画
  7. Android PhotoView 使用教程
  8. Android双击
  9. android menu自定义菜单 Demo
  10. android > 屏蔽掉返回键