以纵向方式启动时,Adobe AIR / Flex应用程序显示空白屏幕

时间:2014-01-07 19:46:01

标签: android actionscript-3 flex air

在我的Flex移动应用程序中,在我的计算机上运行的AIR“adl”模拟器上一切正常。但是当我将应用程序部署到我的Android手机或平板电脑时,我遇到了这个特殊的问题:

该应用程序在横向启动时工作正常,但当我以纵向模式启动它时,它只显示一个空白的白色屏幕。如果我将其旋转为横向模式,它会立即呈现,我可以将其旋转回纵向模式,它仍然有效。

我做了一些调试,看起来当以纵向打开时,视图永远不会被添加到舞台上,甚至达到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()永远不会被调用,直到app处于横向。

- 的更新: 这是我的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>

BTW我正在使用FlashDevelop。

2 个答案:

答案 0 :(得分:0)

在[project] -app.xml文件中,确保您拥有以下行:

<autoOrients>true</autoOrients>

此值默认为false,因此您需要确保已将其设置为让您的应用在两个方向上正确启动。

答案 1 :(得分: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,自定义组件是视图中的最后一个组件,并根据需要从代码中删除并再次添加。在使用时,它覆盖在视图中的其余组件上。它是视图的直接子项,不在组内。也许这会帮助别人。

<强>更新

事实证明,上述并没有完全解决它。我最终还需要删除maxHeight属性。在AS3中设置maxHeight也没有解决它;我不得不完全删除它。

相关问题