Android屏幕分辨率问题
我正在为 Android 编写一款游戏,现在可以在第二台设备 Nexus 1 上对其进行测试。该游戏使用固定像素值,只是在高分辨率设备上使用更大的背景切口。所以我想不会有任何问题。然而,不知何故,Nexus 1 使特定图像变得比应有的更大(261 * 66 而不是 174 * 44)。图片本身作为资源是174*44,所以它被拉伸了。为什么?我能做什么来对抗它?
编辑:
Spritesheet = BitmapFactory.decodeResource(res,
R.drawable.bird_spritesheet);
是使用的代码。
编辑2:
有没有办法告诉软件只使用图片的尺寸?我不想通过添加多张图片(/drawable-hdpi/answer)来使我的软件变得臃肿。
在更大的屏幕上,图片应该更小。
I'm writing a game for Android and can now test it on a second device, the Nexus 1. The game uses fix pixel-values, just using bigger cutouts of the background for high-res devices. So I thought there would be no problems. Somehow, however, the nexus 1 is making a specific image bigger than it should be (261*66 instead of 174*44). The picture itself as a resource is 174*44, so it's being stretched. Why? What can I do against it?
Edit:
Spritesheet = BitmapFactory.decodeResource(res,
R.drawable.bird_spritesheet);
Is the used code.
Edit 2:
Is there no way to tell the software to just use the size the picture is? I don't want to bloat my software by adding multiple pictures (/drawable-hdpi/ answer).
The pictures are supposed to be smaller on bigger screens.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的图片在哪个drawables文件夹中?如果你将它的副本放在drawables-hdpi中,我认为它会显示真实大小。最好以这样的方式进行设置,即最终的像素大小并不重要。使用像素值将确保您的应用程序在至少某些屏幕尺寸上看起来是错误的。
what drawables folder to you have the picture in? If you put a copy of it in drawables-hdpi I think it will show up real size. It is really better to set things up in such as way that the final size in pixels it ends up is unimportant. Using pixels values is going to ensure that your app looks wrong on at least some of the screen sizes out there.
由于 Android 在多种屏幕尺寸上运行,并且您使用设备独立像素 (DIP),因此图像会进行缩放以确保它们在所有设备上看起来都相同。为了避免这种情况,您可以为高密度屏幕(根据您的情况)和低密度屏幕提供替代资源。
有关屏幕的更多信息位于此处
Because Android runs on multiple screen sizes and you use device independent pixels (DIPs), images get scaled to ensure they look the same on all devices. To avoid this, you can provide alternative resources for high density screens (in your case) and for low density screens.
More info about screens here