[英]how android device identifies which layout to use
在我的Android應用程序中,我已經為大屏幕和x大屏幕設置了布局資源,即:layout-large和layout-xlarge。 當我在帶有“大”屏幕的設備仿真器中打開運行它時,它從“ layout-large”文件夾中獲取布局,這似乎是正確的。 但是,當我使用屏幕尺寸為x大的設備時,它仍會使用“ layout-large”資源。
我使用的X大型設備是10英寸,1280x800、240dp仿真器。
我在清單中包括以下內容:
<supports-screens
android:anyDensity="true"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:resizeable="true" />
以下鏈接將幫助您了解android如何在各種設備上拾取布局文件
http://developer.android.com/guide/practices/screens_support.html
您確定文件夾名稱是layout-xlarge
而不是layout-x-large
嗎? DOC
根據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.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.