How to Determine and Set Screen Size at run time u

2019-09-04 11:53发布

Hey so i am developing an android application using action script(the adobe air one) since the screen size of my .swf application is appox 840X480... Can i detect the screen size of the android device running application at runtime and set the screen size accordingly?? if so How?? P.S - I'm still rookie at Action-script Thank You

1条回答
SAY GOODBYE
2楼-- · 2019-09-04 12:12

Basically, to make your app liquid (or responsive). Follow the following steps:

  1. Set the stage align and scale modes:

    stage.scaleMode = StageScaleMode.NO_SCALE;
    stage.align     = StageAlign.TOP_LEFT;
    
  2. Listen for resize events on the stage:

    stage.addEventListener(Event.RESIZE, stageResizeHandler);
    
    function stageResizeHandler(e:Event):void {
        stage.stageWidth; //how big the width is
        stage.stageHeight; //how big the height is.
    
        //so if you had a box, and you wanted it centered on the screen:
        box.x = (stage.stageWidth - box.width) * .5;
        box.y = (stage.stageHeight - box.height) * .5;
    
        //draw a background
        graphics.clear();
        graphics.beginFill(0xFF0000);
        graphics.drawRect(0,0,stage.stageWidth, stage.stageHeight);
        graphics.endFill();
    }
    

If, you just want to know the physical size of the display, you can do so in the Capabilities class:

Capabilities.screenResolutionX;
Capabilities.screenResolutionY;

OR

stage.fullScreenWidth;
stage.fullScreenHeight;

This usually doesn't include any tool bars /notification bars though.

If you just want your content scaled, then set the scale mode to whatever you'd like:

stage.scaleMode = StageScaleMode.NO_BORDER; 
//this will zoom in your app until it fills the whole screen, though it may crop it a bit if needed.

To see other scaling modes, look here

查看更多
登录 后发表回答