2

我正在开发一个在 Google MapView 上显示多个标记的 Android 应用程序。一切正常,但我希望标记出现在地图上时有动画。

这是 iPhone 上类似内容的示例。见 1'20"。

这是我将它们添加到我的 MapView 的方法。

for(int i=0; i<myMarkerList.length(); i++){
GeoPoint x = new GeoPoint(
                (int)(lat*1E6),
                    (int)(lng*1E6));

        oItem = new OverlayItem(x, title, String.valueOf(nb_marker));
        pin.setAlpha(255);
        oItem.setMarker(pin);           

        if (oItem != null)              
            mapOverlay.addOverlay(oItem); // add the overlay item to the overlay            
        }              
        mapOverlays.add(mapOverlay); // add the overlay to the list of overlays
        mapView.invalidate(); // update the map shown

它在 iPhone 上非常漂亮,肯定有人已经在 Android 上做过类似的事情,但我似乎找不到任何有用的信息。

编辑:好的,所以我认为我要么必须重写会很长且不那么漂亮的绘制方法,要么就放弃 OverlayItems。

感谢您的时间。

最好的祝福,

汤姆

4

3 回答 3

0

您可以使用本教程作为参考,它使用动画,所以我认为这适合您的解决方案。

教程中的代码:

//Reference to our MapView
MapView mapView = (MapView) activity.findViewById(R.id.mapview);

//Get a LayoutInflater and load up the view we want to display.
//The false in inflater.inflate prevents the bubble View being added to the MapView straight away
LayoutInflater inflater = activity.getLayoutInflater();
LinearLayout bubble = (LinearLayout) inflater.inflate(R.layout.bubble, mapView, false);

//Set up the bubble's close button
ImageButton bubbleClose = (ImageButton) bubble.findViewById(R.id.bubbleclose);
bubbleClose.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        Animation fadeOut = AnimationUtils.loadAnimation(ResultsMapResultsDisplayer.this.activity, R.anim.fadeout);
        bubble.startAnimation(fadeOut);
        bubble.setVisibility(View.GONE);
    }
});

private void displaySearchResultBubble(final SearchResult result) {
    //Hide the bubble if it's already showing for another result
    map.removeView(bubble);
    bubble.setVisibility(View.GONE);

    //Set some view content
    TextView venueName = (TextView) bubble.findViewById(R.id.venuename);
    venueName.setText(result.getName());

    //This is the important bit - set up a LayoutParams object for positioning of the bubble.
    //This will keep the bubble floating over the GeoPoint result.getPoint() as you move the MapView around,
    //but you can also keep the view in the same place on the map using a different LayoutParams constructor
    MapView.LayoutParams params = new MapView.LayoutParams(
        LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
        result.getPoint(), MapView.LayoutParams.BOTTOM_CENTER);

    bubble.setLayoutParams(params);

    map.addView(bubble);
    //Measure the bubble so it can be placed on the map
    map.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));

    //Runnable to fade the bubble in when we've finished animatingTo our OverlayItem (below)
    Runnable r = new Runnable() {
        public void run() {
            Animation fadeIn = AnimationUtils.loadAnimation(activity, R.anim.fadein);
            bubble.setVisibility(View.VISIBLE);
            bubble.startAnimation(fadeIn);
        }
    };

    //This projection and offset finds us a new GeoPoint slightly below the actual OverlayItem,
    //which means the bubble will end up being centered nicely when we tap on an Item.
    Projection projection = map.getProjection();
    Point p = new Point();

    projection.toPixels(result.getPoint(), p);
    p.offset(0, -(bubble.getMeasuredHeight() / 2));
    GeoPoint target = projection.fromPixels(p.x, p.y);

    //Move the MapView to our point, and then call the Runnable that fades in the bubble.
    mapController.animateTo(target, r);
 }
于 2011-11-18T09:43:11.723 回答
0

我看到了你的示例应用程序。从那我认为你只需要在你的标记中发光,对吧?如果是的话,那么它可能通过样式和它也具有发光属性。

于 2011-11-21T04:50:00.720 回答
0

所以我使用一个简单的 ImageViews ArrayList 和动画,没有 MapOverlay 让它工作。

于 2012-03-01T09:48:49.717 回答