2

我正在开发一个使用谷歌地图的安卓应用程序。我想在 MapView 中显示带有一些坐标的叠加图像。我需要为图像设置动画。请帮忙。我的代码如下

    mapView = (MapView) findViewById(R.id.myGMap);
    mapView.setBuiltInZoomControls(true);
    mapController = mapView.getController();
    mapView.buildDrawingCache();
    mapView.setAnimationCacheEnabled(true);
    mapView.setClickable(true);
    mapView.getZoomLevel();
    mapView.displayZoomControls(true);
    mapView.getMapCenter(); 

    List<Overlay> mapOverlays = mapView.getOverlays();

    drawable = getResources().getDrawable(R.drawable.img1);
    HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable);

    int latitudeE6 = (int)((12.907382) * 1000000);
    int longitudeE6 = (int)((77.595105) * 1000000);
    point = new GeoPoint(latitudeE6,longitudeE6);       
    overlayitem = new OverlayItem(point, "", "");
    mapController.animateTo(point);     
    itemizedoverlay.addOverlay(overlayitem);
    itemizedoverlay.getCenter();
    itemizedoverlay.getFocus();

    mapOverlays.add(itemizedoverlay);
4

2 回答 2

3
public static void addAnimationToMap(MapView map, int animationResourceId, GeoPoint geoPoint)

{   
 final ImageView view = new ImageView(map.getContext());

    view.setImageResource(animationResourceId);

    //Post to start animation because it doesn't start if start() method is called in activity OnCreate method.
    view.post(new Runnable() {
        @Override
        public void run() {
            AnimationDrawable animationDrawable = (AnimationDrawable) view.getDrawable();
            animationDrawable.start();
        }
    });

    map.addView(view);

    MapView.LayoutParams layoutParams = new MapView.LayoutParams(
        MapView.LayoutParams.WRAP_CONTENT,
        MapView.LayoutParams.WRAP_CONTENT,
        geoPoint,
        MapView.LayoutParams.BOTTOM_CENTER);
    view.setLayoutParams(layoutParams);
}

您可以在 res->drawable 中添加动画列表并将可绘制对象传递给此函数。AFAIK 在谷歌地图上添加动画标记的唯一可能方法是在地图上方添加一个视图

于 2012-03-16T07:41:57.163 回答
0

我相信这很难做到,但是您可以使用 drawable 中的 alpha 功能来创建 alpha 动画,如下所示:

drawable.setAlpha();
于 2012-02-27T11:50:05.970 回答