钛处理不同resoutions [英] Titanium handling different resoutions

查看:183
本文介绍了钛处理不同resoutions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单的问题,这是为了确保应用程序在不同屏幕分辨率的作品不看垃圾的最佳方法?我不能用静态值,那么它要根据分辨率调整。现在我使用相对测量(屏幕比例),但不知道这是否真的来处理它的最佳方法!?

Simple question, which is the best way to make sure that the app works on different screen resolutions without looking crap? I can't use static values, then it want adjust according to the resolution. Right now i am using relative measurements (percentage of screen) but wonder if that's really the best way to handle it!?

推荐答案

我们已经成功的另一个/附加选项是一小部分而使用屏幕密度值来计算显示尺寸的功能......这当然只是一个近似值,因为只有四个密度,但我们发现这是非常有帮助的。

Another/additional option we have been successful with is a small set of functions which use the screen density value to compute display sizes... this is of course only an approximation, as there are only the four densities, but we have found this to be very helpful.

//=============================================================================
// inch
//
// compute approximate number of pixels for the specified physical on-screen
// size based on the density reported by the OS
//=============================================================================
function inch(size)
{
    // default to 160 dpi if unavailable
    var height = size * 160.0; 

    try
    { 
        // compute header height based on screen density ... target .25" height
        height = size * Ti.Platform.displayCaps.dpi; 
    }
    catch(e) { warn("Error accessing display caps for screen density calculation: " + e); }

    return height;
}

所以,如果你想要的东西是3/4英寸高的屏幕上......

So if you want something to be 3/4 inch high on the screen....

Ti.UI.createThing({ height: inch(.75)});

...或者,如果你想通过缩放点大小的东西,我们可以做一些常量...

...or if you want to scale things by point size, one could make some constants...

const g_12pt = inch(12/72); //0.166667
const g_10pt = inch(10/72); //0.138889
const g_8pt = inch(8/72);   //0.111111
const g_6pt = inch(6/72);   //0.083333
...
...font:{fontSize: g_10pt, fontWeight:"bold"},...

我们还创建了几个函数来得到屏幕的高度和宽度,所以如果我们在平板电脑上或一些微小的希望有一个更好的布局,我们可以更好地了解我们正在处理。

We also created a couple of functions to get the screen height and width, so if we wanted a better layout on a tablet or something tiny we could better understand what we were dealing with.

//=============================================================================
// screenWidth - return screen width in inches
//=============================================================================
function screenWidth()
{
    return Titanium.Platform.displayCaps.platformWidth / Titanium.Platform.displayCaps.dpi;
}

//=============================================================================
// screenHeight - return screen height in inches
//=============================================================================
function screenHeight()
{
    return Titanium.Platform.displayCaps.platformHeight / Titanium.Platform.displayCaps.dpi;
}

您可以去和从那里...但是这真的帮助我们钉了我们是如何奠定了我们的屏幕上不同的密度和平台。寸函数的异常处理,只是因为我们在早期的应用程序使用它,有时Ti.Platform仍然是不确定的。到时候,我们奠定了我们的报告Ti.Platform可用,所以屏幕的功能没有异常处理。如果您需要提前查询,你可能需要例外处理的那些也。

You can go on and on from there... but this really helped us nail down how we laid out our screens on the different densities and platforms. The inch function has exception handling only because we use it early in the app, and sometimes the Ti.Platform is still undefined. By the time we are laying out our reports Ti.Platform is available and so the screen functions do not have the exception handling. If you need to query earlier you may need exception handling in those as well.

希望这有助于!

这篇关于钛处理不同resoutions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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