Android layout 钛处理不同资源

Android layout 钛处理不同资源,android-layout,titanium,resolution,Android Layout,Titanium,Resolution,简单的问题,哪一个是确保应用程序在不同屏幕分辨率下工作的最好方法,而不会看起来很糟糕?我不能使用静态值,那么它需要根据分辨率进行调整。现在我正在使用相对测量(屏幕百分比),但不知道这是否是处理它的最佳方法 您需要修改tiapp.xml-在android部分添加清单记录,如下所示: <android xmlns:android="http://schemas.android.com/apk/res/android"> <manifest> <s

简单的问题,哪一个是确保应用程序在不同屏幕分辨率下工作的最好方法,而不会看起来很糟糕?我不能使用静态值,那么它需要根据分辨率进行调整。现在我正在使用相对测量(屏幕百分比),但不知道这是否是处理它的最佳方法

您需要修改tiapp.xml-在android部分添加清单记录,如下所示:

<android xmlns:android="http://schemas.android.com/apk/res/android">
    <manifest>
        <supports-screens android:anyDensity="false"/>
    </manifest>
</android>

我们已经成功使用的另一个/附加选项是一组使用屏幕密度值计算显示大小的小函数。。。这当然只是一个近似值,因为只有四个密度,但我们发现这非常有用

//=============================================================================
// 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英寸高的东西

Ti.UI.createThing({ height: inch(.75)});
…或者,如果您想按点大小缩放对象,可以制作一些常量

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"},...
我们还创建了一些函数来获取屏幕的高度和宽度,因此,如果我们想在平板电脑或其他微型设备上获得更好的布局,我们可以更好地了解我们正在处理的问题

//=============================================================================
// 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;
}
你可以从那里继续下去。。。但这确实帮助我们确定了如何在不同密度和平台上布置屏幕。inch函数有异常处理,只是因为我们在应用程序的早期使用它,有时Ti.Platform还没有定义。当我们发布报告时,Ti.Platform已经可用,因此屏幕功能没有异常处理。如果您需要更早地进行查询,您可能还需要在这些查询中进行异常处理


希望这有帮助

好吧,据我在谷歌上搜索到的,解决方案是:

1.检测特定屏幕分辨率:

// app/alloy.js
Alloy.Globals.isIos7Plus = (OS_IOS && parseInt(Ti.Platform.version.split(".")[0]) >= 7);
Alloy.Globals.iPhoneTall = (OS_IOS && Ti.Platform.osname == "iphone" && Ti.Platform.displayCaps.platformHeight == 568); 
2.编写查询样式tss:

// Query styles
"#info[if=Alloy.Globals.isIos7Plus]" : {
    font : { textStyle : Ti.UI.TEXT_STYLE_FOOTNOTE }
},
"#title[if=Alloy.Globals.isIos7Plus]" : {
    top: '25dp', // compensate for the status bar on iOS 7
    font : { textStyle : Ti.UI.TEXT_STYLE_HEADLINE }
},
"#content[if=Alloy.Globals.isIos7Plus]" : {
    font : { textStyle : Ti.UI.TEXT_STYLE_CAPTION1 }
},
"ScrollView[if=Alloy.Globals.iPhoneTall]" : {
    height : '500dp'
}

请参阅:

没问题-Appcelerator提供的关于这类事情的信息量太少了!3.5年过去了,这个问题的答案还是一样吗?钛现在是3.5.0GA,合金也是1.x。