如何在Flex Mobile中的StageWebView下面定位spark List控件

时间:2014-07-29 11:56:20

标签: flex mobile air stagewebview spark-list

我正在使用Flex Mobile开发适用于iOS和Android的移动应用程序。在其中一个视图中,我正在使用Google地图和一个火花List控件显示StageWebView以显示另一个数据。我正在使用StageWebView以受益于Google Maps JavaScript API v3。示例代码如下:

<?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" title="Clubs" backgroundAlpha="0"
    viewActivate="view1_viewActivateHandler(event)"
    backKeyPressed="view1_backKeyPressedHandler(event)"
    initialize="view1_initializeHandler(event)">

<fx:Script>
    <![CDATA[
        import flash.sensors.Geolocation;

        import mx.collections.ArrayCollection;
        import mx.events.FlexEvent;

        import spark.events.ViewNavigatorEvent;
        private var myWebView:StageWebView;
        [Bindable]
        private var locations:ArrayCollection;
        private var geolocation:Geolocation;

        protected function view1_initializeHandler(event:FlexEvent):void
        {
            myWebView = new StageWebView();
            myWebView.stage = this.stage;
        }

        protected function view1_viewActivateHandler(event:ViewNavigatorEvent):void
        {   
            if(Geolocation.isSupported)
            {
                geolocation = new Geolocation();
                geolocation.addEventListener(GeolocationEvent.UPDATE, onGeolocationChange);
            }
        }

        override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{

            super.updateDisplayList(unscaledWidth, unscaledHeight);

            if (myWebView) {
                var point:Point = (new Point());
                point = localToGlobal(point);
                myWebView.viewPort = new Rectangle(point.x,point.y, stage.width,stage.height/3);
            }
        }

        protected function view1_backKeyPressedHandler(event:Event):void
        {
            if (myWebView) 
            {
                myWebView.viewPort = null;
                myWebView = null;
            }

            navigator.popView();
        }

        protected function onGeolocationChange(event:GeolocationEvent):void
        {
            geolocation.removeEventListener(GeolocationEvent.UPDATE, onGeolocationChange);

            locations = new ArrayCollection();
            var location0:Object = new Object();
            location0.lat = event.latitude;
            location0.long = event.longitude;
            locations.addItem(location0);
            var location1:Object = new Object();
            location1.lat = "42.697325";
            location1.long = "23.315364";
            locations.addItem(location1);
            var location2:Object = new Object();
            location2.lat = "42.696441";
            location2.long = "23.321028";
            locations.addItem(location2);



            var url:String = "http://whozzzin.dev.mediatecture.at/gmapsformobile/map.php";

            var counter:Number = 1;

            for each(var location:Object in locations)
            {
                if(counter == 1)
                {   
                    url += "?locations["+counter.toString()+"][lat] = " + location.lat;
                    url += "&locations["+counter.toString()+"][long] = " + location.long;
                }
                else
                {
                    url += "&locations["+counter.toString()+"][lat] = " + location.lat;
                    url += "&locations["+counter.toString()+"][long] = " + location.long;
                }
                counter++;
            }

            myWebView.loadURL(url);

        }


    ]]>
</fx:Script>

<s:navigationContent>
    <s:Button includeInLayout="{Capabilities.version.indexOf('IOS') > -1}" visible="{Capabilities.version.indexOf('IOS') > -1}" id="backButton" label="BACK" click="view1_backKeyPressedHandler(event)"/>
</s:navigationContent>

<s:List width="100%" contentBackgroundAlpha="0" id="placesList" dataProvider="{locations}" labelField="lat">
    <s:layout>
        <s:TileLayout columnWidth="{(width - 16)/3}"/>
    </s:layout>
</s:List>

</s:View>

目前,该列表不可见,因为它出现在StageWebView后面。我的问题是如何在WebStageView之后准确定位List控件。

2 个答案:

答案 0 :(得分:0)

您可以使用top约束:

<s:List width="100%" top="{stage.height/3}" id="placesList"

修改:在trace(stage.height);功能中添加updateDisplayList,并查看stage.stageHeight。这些值应该可以帮助您确定在这种情况下使用的确切top值。

答案 1 :(得分:0)

我是如何解决的:

我得到了WebStageView的底部并将一个新点从全局转换为本地x = 0和y = myWebView.bootom:

        override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{

            super.updateDisplayList(unscaledWidth, unscaledHeight);

            if (myWebView) {
                var point:Point = (new Point(0,this.radiusDropDown.height));
                point = localToGlobal(point);
                myWebView.viewPort = new Rectangle(point.x,point.y, stage.width,stage.height/3);
                this.placesList.y = globalToLocal(new Point(0,myWebView.viewPort.bottom)).y;

            }
        }