2011-10-27 2 views
1

필자는 Adobe AIR 2.6 및 Flash Builder 4.5를 사용하여 Android 용 애플리케이션을 작성하고 있습니다. 모바일 장치 해상도에 따라 리소스를 확장해야합니다. 이를 위해 장치 해상도와 DPI를 알아야합니다. 그러한 코드를 사용하고 있습니다 :플래시 빌더의 AIR 시뮬레이터에서 잘못된 장치 해상도가 발생했습니다.

PlatformUtil.init(mainView.stage.stageWidth, mainView.stage.stageHeight, 
       Capabilities.screenDPI, mainView); 

이 코드를 장치에서 실행할 때 - 모두 OK! 모든 리소스가 올바르게 확장되었습니다 (Nexus One에서). 그러나 플래시 빌더 시뮬레이터에서 내 desctop 컴퓨터에서 실행하고 Google Nexus One 장치에서 선택합니다. 해상도는 800 * 480이어야하지만 코드에서 실제 크기는 500 * 375가됩니다. Capabilities 클래스를 사용하면 1024 * 768 (내 desctop 해상도)을 반환합니다. 그럼 뭐가 잘못 됐어? 왜 장치 해상도가 잘못 되나요? 이 문제를 어떻게 해결할 수 있습니까? 고맙습니다.

+0

확인 : 에어 시뮬레이터는 모든 Android 기기에 대해 해상도 500 * 375를 반환하지만 각각 실제 해상도가 다릅니다. ( – yozhik

답변

6

이 문제는 해결되었습니다. 시뮬레이터는 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(); 
     } 
} 

은 나 같은 사람을 도움이되기를 바랍니다.

3

너비와 높이가 항상 500x375 인 이유는 이것이 mxmlc 컴파일러 (특히 -default-size 옵션)의 기본값이기 때문입니다. 자세한 내용은 여기를 참조하십시오 :

http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_13.html

당신이 앞서 (가능성이) 시간의 모바일 장치의 실제 치수를 알지 못한다면, 당신은 stage.stageHeight를 가져 오는 전에 해고 Event.RESIZE 기다려야합니다. stage 개체에서 Event.RESIZE을 청취해야합니다.

관련 문제