Android的屏幕尺寸算法/模式 [英] Android Screen Size Algorithm / Pattern
问题描述
我在寻找一种算法或模式来计算,其中的对象可放置在多种分辨率。到目前为止,我有X和Y的屏幕尺寸,但林不知道如何把它变成一个计算,将放置在屏幕上的位置的东西如的drawText()无论屏幕大小。
I'm looking for an Algorithm or Pattern to calculate where objects can be placed on multiple resolutions. So far, I have got the X and Y screen size, but im not sure how to turn it into a calculation that would place something such as a drawText() at a location on the screen no matter the screen size.
我是用百分比可能会更容易使用心想也许。我有一个程序,绘制文本到屏幕的左上角,指示位置的屏幕已被触摸。
I was thinking perhaps using percentages might be easier to work with. I have a program that draws text to the screen at the top left corner indicating what position the screen has been touched.
我运行这在模拟器上时,以
when i run this on the emulator, with the
的drawText(资讯,10,10,油漆);
drawText(info, 10,10, paint);
它会显示很大,但是当我在我的手机(Droid 2的全球)运行它的文本的顶部被切断。
it displays great, but when i run it on my phone (Droid 2 Global) the top of the text is cut off.
在短期:
有没有什么办法可以借鉴一些东西到屏幕(使用SurfaceView),将保持在同一个地点在多个屏幕尺寸/ DPI?
Is there any way to draw something to the screen (using SurfaceView) that will remain in the same spot over multiple screen dimensions / dpi?
感谢您的时间。
推荐答案
这是我所见过到目前为止还没有完美的解决方案。
It's no perfect solution that i've seen so far.
我通过指定为特定屏幕比例的特定项目的位置(在模拟器本机屏幕分辨率),然后重新计算它的位置和它在不同的屏幕尺寸上运行,当它放大/缩小遇到了这个问题。
I came across this issue by specifying the position for the particular item for the specific screen ratio(native screen resolution in an emulator), then recalculate its position and scale it up/down when running it in the different screen size.
displayXpos = constDevelopmentScreenXpos (targetDeviceScreenHeight/constDevelopmentScreenHeight) etc..
displayXScale = similarAlgorithm
这是不是最好的,但它给你一些想法。
This is not the best, but it give you some idea.
另外,我填了一些背景'冷宫'区域,选择不关心它,当目标设备X:。Ÿ屏幕比例是开发设备的不同
Also, i fill some 'limbo' area with a background and choose to not care it when the target device X:Y screen ratio is different from development device.
心连心
这篇关于Android的屏幕尺寸算法/模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!