Android Resources Folders by Screen Size

拟墨画扇 提交于 2019-12-04 21:32:04
Aleadam

I believe you're mixing screen size with pixel density:

From the dev guide:

  • 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 small, normal, large, and xlarge. Those for density-specific resources are ldpi (low), mdpi (medium), hdpi (high), and xhdpi (extra high). The qualifiers correspond to the generalized densities described in Range of screens supported, above.
  • The platform also provides a <supports-screens> manifest element, whose attributes android:smallScreens, android:normalScreens, android:largeScreens, and android:xlargeScreens let you specify what generalized screen sizes your application supports. Another attribute, android:anyDensity, lets you indicate whether or not your application includes built-in support for multiple densities.

Edit: added my comments to the response.

Using the example in the comment, the Archos is a 7 inches screen, while the Nexus One has a 3.7 inches screen. At the same number of pixels, the density of pixels is double on the Nexus One. Remember, dpi means dots per inch. That means that the same image would be rendered twice as big in the Archos than in the Nexus One.

The screen size differences should be handled in the layout. Use res/layout-normal for the Nexus One and res/layout-large for the Archos. This way, you will have control over the full layout for the different screen sizes (perhaps you need to limit some widgets that would be unnecessarily large in the Archos) and decide whether you want to keep a fixed size for your drawables or expand them as necessary.

Alternatively, if you really want to keep size proportional to the screen regardless of screen size and without stretching images, then you can create two sets of images, namely image1-normal.png, image2-normal.png and image1-large.png, image2-large.png, etc, both in the res/drawable-mdpi and the res/drawable-hdpi folders, that you would access from the xml files in res/layout-normal and res/layout-large.

In summary, the full requirements should be handled by a combination of layouts and drawables:

  • Nexus One: layout-normal, drawable-hdpi
  • Archos 7: layout-large, drawable-mdpi
  • Xoom: layout-xlarge, drawable-mdpi
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!