按屏幕尺寸排列的 Android 资源文件夹
我开发了一款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
我相信您将屏幕尺寸与像素密度混合在一起:
来自开发指南:
编辑:将我的评论添加到回复中。
使用评论中的示例,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-mdpi
和res/drawable-hdpi
文件夹中来自res/layout-normal
和res/layout-large
中的 xml 文件。总之,完整的要求应该通过布局和可绘制对象的组合来处理:
layout-normal
、drawable-hdpi
layout-large
、drawable-mdpi
layout-xlarge
、<代码>drawable-mdpiI believe you're mixing screen size with pixel density:
From the dev guide:
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 andres/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 theres/drawable-hdpi
folders, that you would access from the xml files inres/layout-normal
andres/layout-large
.In summary, the full requirements should be handled by a combination of layouts and drawables:
layout-normal
,drawable-hdpi
layout-large
,drawable-mdpi
layout-xlarge
,drawable-mdpi