0

我正在使用 MapView addView() 方法向其添加动画视图。

当我这样做时,我的 MapView 中已经有一些 OverlayItems。

当调用 addView() 方法时,我所有的标记都消失了......

知道为什么吗?

    @Override
    public void draw(Canvas canvas, MapView mapView, boolean shadow) {
        app.setMapActivity((Map)context);
        if (!isAnimating)
        {
            if (isNewMarkers(canvas, mapView, shadow))
                isAnimating = true;
            else
                finishDraw(canvas, mapView, shadow);
        }
    }   

    private boolean isNewMarkers(Canvas canvas, MapView mapView, boolean shadow) {
        boolean isNewMarkers = false;
        synchronized (newMarkers) 
        {
            Iterator<OverlayItem> iterator = newMarkers.iterator();         
            while (iterator.hasNext())
            {               
                OverlayItem overlayItem = iterator.next();              
                isNewMarkers = true;                
                animateMarker(canvas, mapView, shadow, overlayItem.getMarker(0), overlayItem.getPoint(),!iterator.hasNext());
            }           
        }       
        fullMapOverlays.addAll(newMarkers);
        newMarkers.clear();
        populate();
        return isNewMarkers;
    }           

    private void animateMarker(Canvas canvas, MapView mapView, boolean shadow, Drawable marker, GeoPoint point, boolean setListener) 
    {               
        Animation animation = AnimationUtils.loadAnimation(app.getMainActivity(), R.anim.map_marker_animiation);
        ImageView imageView = (ImageView) View.inflate(app.getMainActivity(), R.layout.marker_animation, null);
        imageView.setImageDrawable(marker); 

//add view function 
        mapView.addView(imageView, 0, new MapView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, point, MapView.LayoutParams.BOTTOM_CENTER));           
        if (setListener)
            animation.setAnimationListener(new MarkerAnimationListener(canvas, mapView, shadow));
        imageView.startAnimation(animation);
    }


    public void finishDraw(Canvas canvas, final MapView mapView, boolean shadow)
    {
        mapOverlays = createOverlayItems(mapView);
        populate();
        setLastFocusedIndex(-1);        
        super.draw(canvas, mapView, shadow);
        if (mapView.getChildCount()>0)
        {
            mapView.post(new Runnable() {

                @Override
                public void run() {
                    mapView.removeAllViews();                   
                }
            });
        }
    }
    private class MarkerAnimationListener implements AnimationListener
    {

        private MapView mapView;
        private Canvas canvas;
        private boolean shadow;

        public MarkerAnimationListener(Canvas canvas, MapView mapView, boolean shadow)
        {
            this.mapView = mapView;
            this.canvas = canvas;
            this.shadow = shadow;
        }

        @Override
        public void onAnimationEnd(Animation animation) {           
            isAnimating = false;
            finishDraw(canvas, mapView, shadow);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }

        @Override
        public void onAnimationStart(Animation animation) {

        }
    }
}
4

0 回答 0