android设备如何识别要使用的布局

时间:2012-07-18 12:40:42

标签: android

在我的Android应用程序中,我为大屏幕和x大屏幕设置了布局资源,即: layout-large和layout-xlarge。当我在具有“大”屏幕的设备模拟器中打开它时,它从“layout-large”文件夹中获取布局,这似乎是正确的。但是当我使用x大屏幕尺寸的设备时,它仍然使用“布局大”的资源。

我使用的x-large设备是10英寸,1280x800,240dp模拟器。有什么想法吗?

我在清单中包含以下内容:

<supports-screens 
android:anyDensity="true"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:resizeable="true" />

3 个答案:

答案 0 :(得分:2)

下面的链接将帮助您了解Android如何在各种设备上获取布局文件

http://developer.android.com/guide/practices/screens_support.html

答案 1 :(得分:1)

您确定文件夹名称是layout-xlarge而不是layout-x-large吗? DOC

答案 2 :(得分:0)

根据Android文档,用于布局的运行时渲染

  

在运行时,系统确保在当前屏幕上以最佳方式显示任何给定资源的以下过程:

The system uses the appropriate alternative resource

Based on the size and density of the current screen, the system uses any size- and density-specific resource provided in your application. For example, if the device has a high-density screen and the application requests a drawable resource, the system looks for a drawable resource directory that best matches the device configuration. Depending on the other alternative resources available, a resource directory with the hdpi qualifier (such as drawable-hdpi/) might be the best match, so the system uses the drawable resource from this directory.
If no matching resource is available, the system uses the default resource and scales it up or down as needed to match the current screen size and density

The "default" resources are those that are not tagged with a configuration qualifier. For example, the resources in drawable/ are the default drawable resources. The system assumes that default resources are designed for the baseline screen size and density, which is a normal screen size and a medium density. As such, the system scales default density resources up for high-density screens and down for low-density screens, as appropriate.

However, when the system is looking for a density-specific resource and does not find it in the density-specific directory, it won't always use the default resources. The system may instead use one of the other density-specific resources in order to provide better results when scaling. For example, when looking for a low-density resource and it is not available, the system prefers to scale-down the high-density version of the resource, because the system can easily scale a high-density resource down to low-density by a factor of 0.5, with fewer artifacts, compared to scaling a medium-density resource by a factor of 0.75.