按屏幕尺寸排列的 Android 资源文件夹

发布于 11-05 17:59 字数 325 浏览 5 评论 0原文

我开发了一款Android游戏,支持市面上几乎所有的分辨率(240x320、320x480、480x800、480x854、600x1024)。

我的问题是,当我尝试支持平板电脑时,我不明白为什么 Android 将资源划分在不同的文件夹中(hdpi、ldpi、mpdi、large-mdpi,...),而该限定符没有用! 我有几个图形集(根据宽度),但我要疯狂了,例如,使用具有密度 mdpi 或 ldpi 的平板电脑 480x800!不可能到达所有设备。

那么,您知道有什么方法可以在文件夹中划分可绘制对象/位图,但只能通过分辨率访问吗?是的,我知道位图别名,但这不是解决方案。

谢谢

I've deloped an Android game which supports almost resolutions in the market (240x320, 320x480, 480x800, 480x854, 600x1024).

My problem is when I'm trying to support tablets, I don't understand why Android divide the resources in different folders (hdpi, ldpi, mpdi, large-mdpi, ...) when that qualifiers isn't useful!
I have several graphics sets (according width) but I'm going crazy, for example, with the tablets 480x800 with density mdpi or ldpi! It's is impossible reach every device.

So, do you know any way to divide drawables/bitmaps in folders but only accesible through resolution?? Yes, I know Bitmap Alias but it's not the solution.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

昔日梦未散2024-11-12 17:59:36

我相信您将屏幕尺寸与像素密度混合在一起:

来自开发指南:

  • 该平台支持一组资源限定符,让您可以根据需要提供特定于大小和密度的资源。特定大小资源的限定符为 smallnormallargexlarge。特定于密度的资源包括 ldpi(低)、mdpi(中)、hdpi(高)和 xhdpi(超高)。这些限定符对应于上面支持的屏幕范围中描述的广义密度.

  • 该平台还提供了清单元素,其属性 android:smallScreensandroid:normalScreensandroid:largeScreens 和 < code>android:xlargeScreens 允许您指定应用程序支持的通用屏幕尺寸。另一个属性 android:anyDensity 可让您指示您的应用程序是否包含对多种密度的内置支持。

编辑:将我的评论添加到回复中。

使用评论中的示例,Archos 是 7 英寸屏幕,而 Nexus One 是 3.7 英寸屏幕。 在相同像素数量下,Nexus One 的像素密度是其两倍。请记住,dpi 表示每英寸点数。 这意味着相同的图像在 Archos 中渲染的大小是 Nexus One 中的两倍

屏幕尺寸差异应在布局中处理。对于 Nexus One 使用 res/layout-normal,对于 Archos 使用 res/layout-large。这样,您将可以控制不同屏幕尺寸的完整布局(也许您需要限制某些在 Archos 中不必要的大部件),并决定是否要为可绘制对象保留固定尺寸或将其扩展为必要的。

或者,如果您确实希望无论屏幕大小如何都保持大小与屏幕成比例,并且不拉伸图像,那么您可以创建两组图像,即 image1-normal.png、image2-normal.png以及 image1-large.png、image2-large.png 等,均位于您可以访问的 res/drawable-mdpires/drawable-hdpi 文件夹中来自 res/layout-normalres/layout-large 中的 xml 文件。

总之,完整的要求应该通过布局和可绘制对象的组合来处理:

  • Nexus Onelayout-normaldrawable-hdpi
  • Archos 7layout-largedrawable-mdpi
  • Xoomlayout-xlarge、<代码>drawable-mdpi

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文