我有这样一个问题:我正在使用Adobe AIR 2.6和Flash Builder 4.5编写Android应用程序.我需要根据移动设备分辨率扩展我的资源.为此,我需要知道设备分辨率和DPI.我正在使用这样的代码来获取它:
PlatformUtil.init(mainView.stage.stageWidth, mainView.stage.stageHeight,
Capabilities.screenDPI, mainView);
Run Code Online (Sandbox Code Playgroud)
当我在设备上运行此代码时 - 一切正常!所有资源都适当缩放(在Nexus One上).但是,当我在闪存生成器模拟器上的desctop计算机上运行它,并从设备谷歌Nexus One中选择 - 它必须具有分辨率800*480,但在代码中我得到实际大小500*375.当我使用Capabilities类时,它返回1024*768(我的desctop分辨率).那么,它有什么不对吗?为什么它会给我错误的设备分辨率?我怎么解决这个问题?Thanx寻求帮助.
我解决了这个问题.模拟器在Event.RESIZE的处理程序中返回有效的模拟器屏幕分辨率,这可以这样做:
public class Main extends Sprite
{
public function Main()
{
super();
//register to add to stage
this.stage.addEventListener(Event.RESIZE, onResize);
this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
// support autoOrients
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
}
private function onAddedToStage(event:Event):void
{
this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
private function onResize(event:Event):void
{
this.stage.removeEventListener(Event.RESIZE, onResize);
//width must be bigger then height, because we in landscape mode
var w:int = Math.max(this.stage.stageWidth, this.stage.stageHeight);
var h:int = Math.min(this.stage.stageWidth, this.stage.stageHeight);
//draw black background
with( graphics )
{
beginFill(0x0)
drawRect(0,0,w,h);
}
init();
}
}
Run Code Online (Sandbox Code Playgroud)
希望它会帮助像我这样的人.
| 归档时间: |
|
| 查看次数: |
1898 次 |
| 最近记录: |