处理:在Android的背景图像不同的屏幕分辨率 [英] Handling different screen resolutions for background images in Android

查看:300
本文介绍了处理:在Android的背景图像不同的屏幕分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Andr​​oid应用程序(一个基于文本的游戏)使用背景图片了很多,以提供更佳的视觉氛围。例如,如果在游戏中的动作带你进入一个小酒馆,那么你在游戏中获得一个小酒馆的背景图像。这是一个巨大的进步,图形,在沉闷的黑色背景,否则你将得到的。

My Android app (a text-based game) uses background images a lot in order to provide a better visual ambiance. For example, if the action in the game takes you into a tavern, then you get a background image of a tavern in the game. This is a vast improvement, graphically, over the boring black background that you would otherwise get.

有也是一个问题,然而,由于机器人:背景总是一直延伸到屏幕的尺寸。其结果是,背景图像看起来如果纵向和横向模式之间的切换玩家很不好。而更糟糕的是,许多设备有非常不同的纵横比(例如,小320x480 MDPI,480x800的华电国际和480x852华电国际),甚至更多的变化来了。

It is also a problem, however, since android:background always stretches to the dimensions of the screen. The result is that the background images look very bad if the player switches between portrait and landscape mode. And to make matters worse, many devices have very different aspect ratios (e.g., 320x480 mdpi, 480x800 hdpi, and 480x852 hdpi) and even more variations are coming.

如何别人解决这个问题呢?具有独立的图像为主体的分辨率/取向是不是我的选择,因为这将导致APK变得太大。

How do others solve this problem? Having individual images for the main resolutions/orientations is not an option for me, as this would result in the apk growing too large.

推荐答案

我会建议你让你的当前视图的宽度和高度。现在,我不知道什么功能会给你这些价值观,但我相信这是可能的。这样,您就可以计算出的纵横比。我使图像像1000×1000和只显示图像的特定部分,以使宽高比不会有错。
我有同样的问题与相机。所以我的解决办法是挑两个值,宽度或高度之一,为固定的,并根据该纵横比计算出正确的其它值。我不知道是否有功能已经只显示图像的一部分,但我相信你可以写的东西复制图像的只是一部分,并表明部分。

I would suggest you get the width and height of your current view. Right now I am not sure what functions will give you these values but I am sure it is possible. With that you can then calculate an aspect ratio. I'd make the images something like 1000x1000 and just show a certain part of the image, so that the aspect ratio will not be wrong.
I have the same problem with the camera. So my solution was to pick one of the two values, width or height, as fixed, and calculate the correct other value according to the aspect ratio. I'm not sure if there are functions already to just show a part of the image, but I am sure you could write something to copy just a part of the image and show that part.

缺点是当然,你会呈现出的背景只是一个部分。由于手机的总的方面比不过地方1之间:1.3和1:1.8我想这不会是一个太大的问题。作为个人,我宁愿看到图像的一部分以正确的方式,不是在寻找一个丑陋的拉伸图像。

The drawback is of course that you will be showing just a part of the background. Since the general aspect ratio of the phones is however somewhere between 1:1.3 and 1:1.8 I guess it wouldn't be a too big problem. I for one would rather see the part of an image in the correct way, than looking at an ugly stretched image.

这篇关于处理:在Android的背景图像不同的屏幕分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆