在 Kindle Fire 上使用 HDPI 资源
我目前正在考虑让我的 Android 应用程序在 Kindle Fire 上运行。我有 MDPI 和 HDPI 屏幕的图稿,但我注意到,当我在 Kindle 上加载应用程序时,它会显示 MDPI 图稿并拉伸我的一些图稿,而我向家长填充的图稿比我想要的多了一点。
我想知道 Android 上是否有任何方法可以在某些情况下(比如我在 Kindle 上)强制它从 HDPI 图稿加载,而不是默认为 MDPI。
我确实意识到我可以将我的 HDPI 图稿保存在 MDPI 文件夹中,并使用稍微不同的名称,并对每个资源进行检查,但这是很大的开销,更不用说我的应用程序大小的增加了,我' d也想避免。
谢谢
更新:仍在关注这个。我想我真正想要的是什么,有没有办法让 Android 设备选择 HDPI 图稿而不是 MDPI,即使 MDPI 图稿存在?
I'm currently looking into getting my android app to work on Kindle Fire. I've got artwork for both MDPI and HDPI screens, but I noticed that when I load the app up on the Kindle, it displays the MDPI artwork and stretches some of my artwork that I'm filling parent with a little more than I want.
I was wondering if there's any way on Android to under certain circumstances (like if I'm on a Kindle), force it to load from the HDPI artwork, instead of defaulting to MDPI.
I do realize that I could just save my HDPI artwork in the MDPI folder with a slightly different name and do a check for every resource, but that's a lot of overhead, not to mention an increase in the size of my app, which I'd also like to avoid.
Thanks
Update: Still looking at this one. I guess what I'm really getting at, is there a way for an android device to chose HDPI artwork instead of MDPI, even though the MDPI artwork exists?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Kindle Fire 的分辨率为 1024x600、160 dpi,对吧?
您可以使用该分辨率尝试新资源。并将它们放在 MDPI 文件夹中。
在 /res 目录中添加 layout-large 并将布局文件复制到那里。
这样,在 Kindle Fire 中,您可以使用布局大的布局来指向 MDPI 文件夹中更大的资源。
并确保您始终使用九补丁可绘制资源。
希望这对您有帮助。
The Kindle Fire is 1024x600 with 160 dpi, right?
You can try new resourses with that resolution. And place them in the MDPI folder.
Add layout-large at /res directory and copy your layout file there.
That way, with the Kindle Fire, you use the layout at layout-large pointing to bigger resources in the MDPI folder.
And make sure you always use nine-patch drawables for resources.
Hope this helps you.
同时最终使用了黑客解决方案,但我遇到了这个:
我不希望 Android 自动调整我的位图大小
几乎只需要将我的 hdpi 图像移动到 nodpi 文件夹中(以避免缩放问题)并稍微更改名称(我添加了一个_hd 到名称)。之后,我制作了一个图像加载器,它接受我想要的图像的名称,如果设备是 hdpi 或者是 kindle fire,则返回 _hd 图像:
注意:文档确实不鼓励使用 getIdentifier(),因为它的效率低于只是使用资源地址,但我查看了加载时间,使用 getIdentifier 加载 1000 个图像需要 0.25 秒,这对我来说很好,特别是因为我没有加载任何接近那么多图像的地方。
Ended up using a hack solution in the meantime, but I came across this:
I don't want Android to resize my bitmap Automatically
Pretty much just needed to move my hdpi images into the nodpi folder (in order to avoid the scaling issues) and changed the names slightly (I added a _hd to the name). After that I made an image loader that takes in the name of the image I want and returns _hd images if device is hdpi or if it's kindle fire:
Note: The docs do discourage the use of getIdentifier(), as it is less efficient than just using the resource address, but I took a look at the load times and loading 1000 images with getIdentifier takes .25 seconds, which is fine with me especially since I'm not loading anywhere close to that many images.
您可以尝试具有该分辨率的新资源并将其放置在
MDPI
文件夹中。在/res
目录中添加layout-large
并将布局文件复制到那里。这样,在 Kindle Fire 中,您可以使用layout-large
的布局指向MDPI
文件夹中的更大资源。You can try new resources with that resolution and place them in the
MDPI
folder. Addlayout-large
at/res
directory and copy your layout file there. That way, with the Kindle Fire, you use the layout atlayout-large
pointing to bigger resources in theMDPI
folder.