-1

地図上でマーカー/ピン/オーバーレイアイコンをアニメーション化する方法を教えてください。過去2日間からたくさん試しましたが、うまくいきません。

前もって感謝します..

動作しない

res / drawable / map_marker.xml

 <?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
 android:oneshot="false">
<item android:drawable="@drawable/ecall_lowon" android:duration="200" />
<item android:drawable="@drawable/ecall_mediumoff" android:duration="200" />

Javaコード

    Drawable drawable = this.getResources().getDrawable(R.drawable.map_marker);
    MapItemizedOverlay mapItemizedOverlay = new MapItemizedOverlay(drawable, this);

    GeoPoint geoPoint1 = new GeoPoint((int)(9.982878 * 1E6), (int)(76.285774 * 1E6));
    GeoPoint geoPoint2 = new GeoPoint((int)(9.973928 * 1E6), (int)(76.276824 * 1E6));

    OverlayItem overlayItem1 = new OverlayItem(geoPoint1, "Title1", "");
    OverlayItem overlayItem2 = new OverlayItem(geoPoint2, "Title2", "");

    mapItemizedOverlay.addOverlayItems(overlayItem1);
    mapItemizedOverlay.addOverlayItems(overlayItem2);

    mapView.getOverlays().add(mapItemizedOverlay);

しかし、成功していません...

4

1 に答える 1

5

An animation defined in XML that shows a sequence of images in order (<animation-list />) may not work to show blink pin on map

I have work around this and find one of the solutions

Idea: Two drawables.., Runnable and handler, SetPin_On() and SetPin_Off(), In SetPin_On method use one image and in SetPin_Off method use another image,on each function calling clear overlay and add again

Resources: Take two images say pin_on, pin_off

Coding: Runnable with handler is required to set the pins in intervals

Example:

Handler handler=new Handler();
      int check=0;

          Runnable r=new Runnable()
          {

        @Override
        public void run() 
        {
             if(check==0)
             {
               SetPin_On();
               check=1;

             }
             else if(check==1)
             {
               SetPin_Off();
               check=0;
             }
            handler.postDelayed(this, 500);
        }

    };

And in SetPin_On method set the pin_on image on overlay and in SetPin_Off method again set pin_off image by clearing previous overlay

SetPin_On:

void SetPin_On()
    {
         mapOverlays = mapView.getOverlays();
         mapOverlays.clear(); 

         res =getResources(); 
         drawable = res.getDrawable(R.drawable.pin_on);
         itemizedOverlay = new CustomItemizedOverlay(drawable,this, mapView);


         point = new GeoPoint((int)(Double.parseDouble(lati)*1E6),(int)(Double.parseDouble(longi)*1E6));
         overlayitem = new OverlayItem(point, "Hello", "I'm in Athens, Greece!");

         itemizedOverlay.addOverlay(overlayitem);
         mapOverlays.add(itemizedOverlay);

         mapController = mapView.getController();

         mapController.animateTo(point);
         mapController.setZoom(6);
    }

SetPin_Off:

void SetPin_Off()
    {

        mapOverlays = mapView.getOverlays();
         mapOverlays.clear(); 

         res =getResources(); 
         drawable = res.getDrawable(R.drawable.pin_off);
         itemizedOverlay = new CustomItemizedOverlay(drawable,this, mapView);


         point = new GeoPoint((int)(Double.parseDouble(lati)*1E6),(int)(Double.parseDouble(longi)*1E6));
         overlayitem = new OverlayItem(point, "Hello", "I'm in Athens, Greece!");

         itemizedOverlay.addOverlay(overlayitem);
         mapOverlays.add(itemizedOverlay);

         mapController = mapView.getController();

         mapController.animateTo(point);
         mapController.setZoom(6);

    }

This is one solution to get blinking pin.May not efficient but result is very accurate

See here for another solution

于 2012-08-29T06:28:47.543 に答える