2014-01-07 106 views
2

在我的Flex移動應用程序中,我的計算機上運行的AIR「adl」模擬器上的一切都很好。但是當我將應用程序部署到我的Android手機或平板電腦時,我遇到了這個奇怪的問題:Adob​​e AIR/Flex應用程序在縱向啓動時顯示空白屏幕

該應用程序在橫向啓動時工作正常,但是當我以縱向模式啓動它時,它只顯示空白的白色屏幕。如果將其旋轉到橫向模式,它會立即渲染,並且可以將其旋轉回縱向模式,並且仍然可以工作。

我做了一些調試,看起來在縱向打開時,視圖永遠不會被添加到舞臺上,甚至可以達到creationComplete。但是如果我旋轉成風景,它會立即做到。

任何想法?

Main.mxml

<?xml version="1.0" encoding="utf-8"?> 
<s:ViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
          xmlns:s="library://ns.adobe.com/flex/spark" 
          firstView="views.HomeView"> 

<fx:Metadata> 
    [ResourceBundle("resources")] 
</fx:Metadata> 

<!-- Global CSS styles --> 
<fx:Style source="styles/AppStyles.css" /> 

<fx:Script> 
    <![CDATA[ 
    // Initialize some vars... 
    ]]> 
</fx:Script> 

<fx:Declarations> 
    <!-- Place non-visual elements (e.g., services, value objects) here --> 
</fx:Declarations> 

</s:ViewNavigatorApplication> 

查看/ HomeView.mxml

<?xml version="1.0" encoding="utf-8"?> 
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:components="components.*" 
    creationComplete="init()" menuKeyPressed="handleMenuKeyPressed(event)" 
    title="..."> 
<s:states> 
    <s:State name="portrait" /> 
    <s:State name="landscape" /> 
</s:states> 

<fx:Script source="ViewHandler.as" /> 
<fx:Script source="HomeViewHandler.as" /> 
<fx:Style source="../styles/HomeViewStyles.css" /> 

..... 
<s:Label id="resultsHeading" text="{s('Results')}" fontWeight="bold" addedToStage="setResultsHeadingFont()" /> 
    <s:HGroup width="100%" layoutDirection="{s('layoutDirection')}"> 
     <s:Group id="mainResultsGroup" width="90%"> 
      <s:layout.portrait> 
       <s:VerticalLayout /> 
      </s:layout.portrait> 
      <s:layout.landscape> 
       <s:HorizontalLayout gap="{getScaledNumber(100)}" /> 
      </s:layout.landscape> 
      <s:VGroup> 
..... 

這裏init()不會被調用,直到應用程序爲橫向。

- 更新: 這裏是我的application.xml:

<?xml version="1.0" encoding="utf-8"?> 
<application xmlns="http://ns.adobe.com/air/application/4.0"> 
    <id>com.myapp</id> 
    <versionNumber>0.1</versionNumber> 
    <supportedProfiles>mobileDevice</supportedProfiles> 
    <filename>MyApp</filename> 
    <name> 
    <text xml:lang="en">My App</text> 
    </name> 
    <android> 
    <manifestAdditions><![CDATA[<manifest android:installLocation="auto"> 
    <uses-sdk android:minSdkVersion="8" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-feature android:required="true" android:name="android.hardware.touchscreen.multitouch" /> 
</manifest>]]></manifestAdditions> 
    </android> 
    <iPhone> 
    <InfoAdditions><![CDATA[<key>UIStatusBarStyle</key> 
<string>UIStatusBarStyleBlackOpaque</string> 
<key>UIRequiresPersistentWiFi</key> 
<string>NO</string> 
<key>UIPrerenderedIcon</key> 
<true /> 
<key>UIApplicationExitsOnSuspend</key> 
<true /> 
<key>UIDeviceFamily</key> 
<array> 
    <!-- iPhone support --> 
    <string>1</string> 
    <!-- iPad support --> 
    <!--<string>2</string>--> 
</array>]]></InfoAdditions> 
    <requestedDisplayResolution>high</requestedDisplayResolution> 
    </iPhone> 
    <initialWindow> 
    <title>My App</title> 
    <content>MyApp.swf</content> 
    <visible>true</visible> 
    <fullScreen>false</fullScreen> 
    <autoOrients>true</autoOrients> 
    <!--<aspectRatio>landscape</aspectRatio>--> 
    <renderMode>cpu</renderMode> 
    <systemChrome>standard</systemChrome> 
    </initialWindow> 
    <icon> 
    <image48x48>icons/icon_48.png</image48x48> 
    <image57x57>icons/icon_57.png</image57x57> 
    <image72x72>icons/icon_72.png</image72x72> 
    <image96x96>icons/icon_96.png</image96x96> 
    <image114x114>icons/icon_114.png</image114x114> 
    <image144x144>icons/icon_144.png</image144x144> 
    <!--<image512x512>icons/icon_512.png</image512x512>--> 
    </icon> 
    <description> 
    <text xml:lang="en"> 
    </text> 
    </description> 
</application> 

順便說一句,我使用的FlashDevelop。

+0

你可以發佈你的'[Main] -app.xml'文件嗎?我認爲可能沒有適當地設置「」或「」的值。 – Brian

+0

@Brian I更新並添加它。 – SZH

+0

你在用什麼「景觀」和「肖像」國家? –

回答

0

我終於搞定了,我無法解釋這是如何或爲什麼會起作用。

我在HomeView.mxml底部的自定義組件:

<components:MyCustomComp id="customComp" right="0" left="0" bottom="0" 
         height="40%" maxHeight="700" /> 

當我height屬性設置爲一個數字,而不是百分比,一切工作正常。但我想要一個百分比,所以我忽略了MXML中的height屬性,並且當我初始化視圖時,我設置了customComp.percentHeight = 40;,並且它神奇地加載完美。

有時候真的Flex的困擾我...

FWIW,自定義組件是最後的視圖,並從代碼需要被刪除並重新添加。在使用時,它覆蓋視圖中其餘的組件。這是一個直接的觀點,不在集團內部。也許這會幫助別人。

UPDATE

事實證明,上面並沒有完全解決它。我最終還需要刪除maxHeight屬性。在AS3中設置maxHeight也沒有解決它;我必須完全刪除它。

0

在你的[項目] -app.xml文件時,請確保您有以下行:

<autoOrients>true</autoOrients> 

此值默認爲false,所以你需要確保你已經設定,爲您的應用程序在兩個方向上正確啓動。

+0

它設置爲true。我更新了我的問題並添加了整個application.xml文件。 – SZH

相關問題