flex air 不同分辨率下启动图像
移动设备应用程序中的第一个标签通常是以下标签之一:
开发用于平板电脑的应用程序时,屏幕大小限制并不像在手机应用程序中那样重要。因此,对于平板电脑,不需要以小视图来构建应用程序。可以使用标准 Spark Application 容器以及受支持的移动设备组件和外观来构建应用程序。
注:?在开发任何移动设备应用程序时(即使是用于移动设备的程序),都可以使用 Spark Application 容器。但是,Spark Application 容器不支持视图导航、数据持久化机制、设备的后退和菜单按钮。有关更多信息,请参阅
关于 Application 容器的
移动设备应用程序容器与 Spark Application 容器的区别。
移动设备应用程序容器具有以下默认的特性:
移动设备应用程序容器与 Spark Application 容器的区别Spark 移动设备应用程序容器的大部分功能与 Spark Application 容器相同。例如,可以对移动设备应用程序容器应用样式,其方法与 Spark Application 容器的样式应用方法相同。 Spark 移动设备应用程序容器有一些与 Spark Application 容器不同的特征:
有关 Spark 应用程序容器的更多信息,请参阅?About the Application container。 处理应用程序级别的事件NativeApplication 类代表一个 AIR 应用程序。它负责提供应用程序信息和应用程序级功能,并分派应用程序级事件。可以使用静态属性?NativeApplication.nativeApplication?来访问与移动设备应用程序对应的 NativeApplication 类的实例。 例如,NativeApplication 类定义了可以在移动设备应用程序中处理的?invoke?和?exiting?事件。下面的示例引用该 NativeApplication 类,来定义?exiting?事件的事件处理函数: <?xml version="1.0" encoding="utf-8"?> <!-- containersmobileSparkNativeApplicationEvent.mxml --> <s:ViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" firstView="views.EmployeeMainView" creationComplete="creationCompleteHandler(event);"> <fx:Script> <![CDATA[ import mx.events.FlexEvent; protected function creationCompleteHandler(event:FlexEvent):void { // Reference NativeApplication to assign the event handler. NativeApplication.nativeApplication.addEventListener(Event.EXITING,myExiting); } protected function myExiting(event:Event):void { // Handle exiting event. } ]]> </fx:Script> </s:ViewNavigatorApplication> 请注意,需使用?ViewNavigatorApplication.navigator?属性来访问 ViewNavigator。 在应用程序中添加启动屏幕Spark Application 容器是 ViewNavigatorApplication 和 TabbedViewNavigatorApplication 容器的基类。用于 Spark 主题时,Spark Application 容器支持应用程序预加载器,以显示应用程序 SWF 文件的下载和初始化进度。 用于 Mobile 主题时,则可以显示启动屏幕。启动屏幕在应用程序启动期间显示。
注:?要在桌面应用程序中使用启动屏幕,请将?
Application.preloader?属性设置为 spark.preloaders.SplashScreen。同时将 frameworkslibsmobilemobilecomponents.swc 添加到应用程序的库路径中。
从图像文件中添加启动屏幕可以直接从图像文件中加载启动屏幕。要配置启动屏幕,请使用应用程序类的?splashScreenImage、splashScreenScaleMode?和?splashScreenMinimumDisplayTime?属性。 例如,以下示例从使用信箱格式的 JPG 文件中加载启动屏幕。 <?xml version="1.0" encoding="utf-8"?> <!-- containersmobileSparkMobileSplashScreen.mxml --> <s:ViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" firstView="views.EmployeeMainView" splashScreenImage="@Embed('assets/logo.jpg')" splashScreenScaleMode="letterbox"> </s:ViewNavigatorApplication> 从自定义组件中添加启动屏幕上一部分中的示例使用 JPG 文件定义启动屏幕。该机制的缺点是:无论运行应用程序的移动设备具有什么功能,应用程序都使用相同的图像。 移动设备具有不同的屏幕分辨率和大小。您可以定义自定义组件,而不是将单个图像用作启动屏幕。此组件决定着移动设备的功能并将合适的图像用作启动屏幕。 使用?SplashScreenImage?类定义自定义组件,如下例所示: <?xml version="1.0" encoding="utf-8"?> <!-- containersmobilemyComponentsMySplashScreen.mxml --> <s:SplashScreenImage xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"> <!-- Default splashscreen image. --> <s:SplashScreenImageSource source="@Embed('../assets/logoDefault.jpg')"/> <s:SplashScreenImageSource source="@Embed('../assets/logo240Portrait.jpg')" dpi="240" aspectRatio="portrait"/> <s:SplashScreenImageSource source="@Embed('../assets/logo240Landscape.jpg')" dpi="240" aspectRatio="landscape"/> <s:SplashScreenImageSource source="@Embed('../assets/logo160.jpg')" dpi="160" aspectRatio="portrait" minResolution="960"/> </s:SplashScreenImage> 在组件定义内,使用?SplashScreenImageSource?类定义每个启动屏幕图像。SplashScreenImageSource.source?属性指定图像文件。SplashScreenImageSource?dpi、aspectRatio?和?minResolution?属性定义显示图像所需的移动设备功能。 例如,第一个 SplashScreenImageSource 定义仅指定图像的?source?属性。由于没有用于?minResolution?属性的设置,此图像可以在任何设备上使用。因此,它可以定义在没有其它图像与设备功能相符时显示的默认图像。 第二和第三个 SplashScreenImageSource 定义指定在纵向或横向模式下用于 240 DPI 设备的图像。 最后一个 SplashScreenImageSource 定义指定在纵向模式下用于 160 DPI 设备、最低分辨率为 960 像素的图像。minResolution?属性的值与?Stage.stageWidth?和?Stage.stageHeight?属性值中的较大值进行对照。这两个值中的较大值必须等于或大于?minResolution?属性。 以下移动设备应用程序使用此组件: <?xml version="1.0" encoding="utf-8"?> <!-- containersmobileSparkMobileSplashComp.mxml --> <s:ViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" firstView="views.EmployeeMainView" splashScreenImage="myComponents.MySplashScreen"> </s:ViewNavigatorApplication> SplashScreenImage 类自动确定与设备功能最匹配的图像。此匹配操作基于每个 SplashScreenImageSource 定义的?minResolution?属性。 决定最佳匹配项的步骤如下所示:
显式选择启动屏幕图像SplashScreenImage.getImageClass()?方法决定与移动设备功能最匹配的 SplashScreenImageSource 定义。您可以重写此方法以添加自己的自定义逻辑,如下例所示。 在该示例中,添加用于 iOS 启动屏幕的 SplashScreenImageSource 定义。在重写?getImageClass()?方法的主体中,首先确定应用程序是否在 iOS 中运行。如果是这样,显示特定于 iOS 的图像。 如果应用程序未在 iOS 中运行,则调用?super.getImageClass()?方法。此方法使用默认实现决定要显示的 SplashScreenImageSource 实例: <?xml version="1.0" encoding="utf-8"?> <!-- containersmobilemyComponentsMyIOSSplashScreen.mxml --> <s:SplashScreenImage xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"> <fx:Script> <![CDATA[ // Override getImageClass() to return an image for iOS. override public function getImageClass(aspectRatio:String,dpi:Number,resolution:Number):Class { // Is the application running on iOS? if (Capabilities.version.indexOf("IOS") == 0) return iosImage.source; return super.getImageClass(aspectRatio,dpi,resolution); } ]]> </fx:Script> <!-- Default splashscreen image. --> <s:SplashScreenImageSource source="@Embed('../assets/logoDefault.jpg')"/> <s:SplashScreenImageSource source="@Embed('../assets/logo240Portrait.jpg')" dpi="240" aspectRatio="portrait"/> <s:SplashScreenImageSource source="@Embed('../assets/logo240Landscape.jpg')" dpi="240" aspectRatio="landscape"/> <s:SplashScreenImageSource source="@Embed('../assets/logo160.jpg')" dpi="160" aspectRatio="portrait" minResolution="960"/> <!-- iOS splashscreen image. --> <s:SplashScreenImageSource id="iosImage" source="@Embed('../assets/logoIOS.jpg')"/> </s:SplashScreenImage> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |