【问题标题】:Adobe AIR / Flex app shows blank white screen when started in portraitAdobe AIR / Flex 应用程序在纵向启动时显示空白屏幕
【发布时间】:2014-01-07 19:46:00
【问题描述】:

在我的 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() 直到应用程序处于横向时才会被调用。

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

【问题讨论】:

  • 您能发布您的[Main]-app.xml 文件吗?我认为&lt;aspectRatio&gt;&lt;autoOrients&gt; 的值可能设置不正确。
  • @Brian 我更新并添加了它。
  • 您使用landscapeportrait 状态做什么?
  • 尝试在您的应用程序和视图类中添加preinitializeinitialize 侦听器;用这些调试可能会给你更多的线索。
  • @JoshJanusch 我用该代码更新了问题。我用它来选择布局类型

标签: android actionscript-3 apache-flex air


【解决方案1】:

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

<autoOrients>true</autoOrients>

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

【讨论】:

  • 设置为真。我更新了我的问题并添加了整个 application.xml 文件。
【解决方案2】:

我终于让它工作了,但我无法解释它是如何工作的,或者为什么工作。

我在 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 也没有修复它;我必须完全删除它。

【讨论】:

    猜你喜欢
    • 2016-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多