-1

我正在使用 Flex Mobile 为 iOS 和 Android 开发移动应用程序。在其中一个视图中,我使用 Google 地图和 spark 列表控件显示 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 后面。我的问题是如何将 List 控件准确定位在 WebStageView 之后。

4

2 回答 2

0

您可以使用top约束:

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

trace(stage.height);编辑:在您的函数中放入 aupdateDisplayList并查看stage.stageHeight. top这些值应该可以帮助您确定在这种情况下要使用的确切值。

于 2014-07-29T20:32:10.527 回答
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;

            }
        }
于 2014-07-31T08:45:34.657 回答