0

ausgeführt werden Ich versuche, eine Atmeffektanimation auf meinem MapFragment zu erzielen, aber aus irgendeinem Grund kann ich nicht mehrere Animationen auf der Karte ausführen. Was ich versuche zu erreichen ist so etwas wie dieses:Nultuple Animationen können nicht auf GroundOverlay [GoogleMap]

enter image description here

Und die Kreise erweitern allmählich und Verblassen zu tun. Gerade jetzt meine Animation tut dies:

enter image description here

die nicht ganz ist, was ich will. Der aktuelle Code (wenn ich die 2 Blöcke mit den Handlern auskommentiere) macht nur eine Animation und der Rest der Formen bleibt stationär. EDIT Ich habe herausgefunden, was passiert - die "startAnimation" -Methode überschreibt die aktuelle Animation. Jetzt frage ich mich, ob es einen Weg gibt, wie ich dieses Übersteuern vermeiden kann? Irgendwelche Ideen ?:

enter image description here

Dies ist mein Code:

@Override 
    public void onMapReady(GoogleMap googleMap) { 
     mMap = googleMap; 

//Add smallest image drawable overlay 

     mDotMarkerBitmap = generateBitmapFromDrawable(R.drawable.circle_drawable); 
     groundOverlay = mMap.addGroundOverlay(new GroundOverlayOptions() 
       .image(BitmapDescriptorFactory.fromBitmap(mDotMarkerBitmap)) 
       .position(xDesign, 100)); 
     groundAnimation = new RadiusAnimation(groundOverlay); 
     groundAnimation.setRepeatCount(Animation.INFINITE); 
     groundAnimation.setRepeatMode(Animation.RESTART); 
     groundAnimation.setDuration(2000); 
     mapFragment.getView().startAnimation(groundAnimation); // MapView where i show my map 
//TODO Fix the animation tomorrow 
//Add medium size image drawable overlay 

//  new Handler().postDelayed(new Runnable() { 
//   @Override 
//   public void run() { 
//    // your code here 
//    mDotMarkerBitmap = generateBitmapFromDrawable(R.drawable.circle_drawable2); 
//    groundOverlay = mMap.addGroundOverlay(new GroundOverlayOptions() 
//      .image(BitmapDescriptorFactory.fromBitmap(mDotMarkerBitmap)) 
//      .position(xDesign, 100)); 
//    groundAnimation = new RadiusAnimation(groundOverlay); 
//    groundAnimation.setRepeatCount(Animation.INFINITE); 
//    groundAnimation.setRepeatMode(Animation.RESTART); 
//    groundAnimation.setDuration(10000); 
//    mapFragment.getView().startAnimation(groundAnimation); // MapView where i show my map 
//   } 
//  }, 1000/* 1sec delay */); 

// 
////Add smallest size image drawable overlay 
//  new Handler().postDelayed(new Runnable() 
//  { 
//   @Override 
//   public void run() 
//   { 
//    // your code here 
//    mDotMarkerBitmap = generateBitmapFromDrawable(R.drawable.circle_drawable3); 
//    groundOverlay = mMap.addGroundOverlay(new GroundOverlayOptions() 
//      .image(BitmapDescriptorFactory.fromBitmap(mDotMarkerBitmap)) 
//      .position(xDesign, 100)); 
//    groundAnimation = new RadiusAnimation(groundOverlay); 
//    groundAnimation.setRepeatCount(Animation.INFINITE); 
//    groundAnimation.setRepeatMode(Animation.RESTART); 
//    groundAnimation.setDuration(2000); 
//    mapFragment.getView().startAnimation(groundAnimation); // MapView where i show my map 
//   } 
//  }, 1000/* 1sec delay */); 



     mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(xDesign, 15)); 
    } 

circle_drawable.xml (circle_drawable2 und 3 gleich außer der Breite & Höhenwerte, sie sind größer 60 und 90dp und die Farben - blau und rot):

<?xml version="1.0" encoding="utf-8"?> 
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="oval"> 
    <solid 
     android:color="#0093e8"/> 
    <size 
     android:width="30dp" 
     android:height="30dp"/> 
</shape> 

RadiusAnimation Klasse:

public class RadiusAnimation extends Animation { 
    private GroundOverlay groundOverlay; 

    public RadiusAnimation(GroundOverlay groundOverlay) { 
     this.groundOverlay = groundOverlay; 

    } 
    @Override 
    protected void applyTransformation(float interpolatedTime, Transformation t) { 
     groundOverlay.setDimensions((100 * interpolatedTime)); 
     groundOverlay.setTransparency(interpolatedTime); 

    } 


    @Override 
    public void initialize(int width, int height, int parentWidth,int parentHeight) { 
     super.initialize(width, height, parentWidth, parentHeight); 
    } 
} 

Antwort

0

Falls jemand etwas Ähnliches versucht, habe ich die Lösung gefunden. Um mehrere Animationen gleichzeitig ausführen zu können, kann ich AnimationSet verwenden. Also entfernte ich die Handler, die die einzelnen Animationen verzögerten, aber da jeder den letzten löschte, funktionierte es nicht und ich sah, dass der letzte hinzugefügt wurde, der auf dem mapFragment spielte. So änderte ich meinen Code so:

public void onMapReady(GoogleMap googleMap) { 
     mMap = googleMap; 


//Add smallest image drawable overlay 

     Bitmap mDotMarkerBitmap1 = generateBitmapFromDrawable(R.drawable.circle_drawable); 

     GroundOverlay groundOverlay1 = mMap.addGroundOverlay(new GroundOverlayOptions() 
       .image(BitmapDescriptorFactory.fromBitmap(mDotMarkerBitmap1)) 
       .position(xDesign, 100)); 

     groundAnimation = new RadiusAnimation(groundOverlay1); 
     groundAnimation.setRepeatCount(Animation.INFINITE); 
     groundAnimation.setRepeatMode(Animation.RESTART); 
     //  groundAnimation.setDuration(700); 
     breadingAnimations.addAnimation(groundAnimation); 


     Bitmap mDotMarkerBitmap2 = generateBitmapFromDrawable(R.drawable.circle_drawable2); 
     GroundOverlay groundOverlay2 = mMap.addGroundOverlay(new GroundOverlayOptions() 
       .image(BitmapDescriptorFactory.fromBitmap(mDotMarkerBitmap2)) 
       .position(xDesign, 100)); 

     Animation groundAnimation2 = new RadiusAnimation(groundOverlay2); 
     groundAnimation2.setRepeatCount(Animation.INFINITE); 
     groundAnimation2.setRepeatMode(Animation.RESTART); 
     //  groundAnimation2.setDuration(900); 
     breadingAnimations.addAnimation(groundAnimation2); 


     Bitmap mDotMarkerBitmap3 = generateBitmapFromDrawable(R.drawable.circle_drawable3); 
     GroundOverlay groundOverlay3 = mMap.addGroundOverlay(new GroundOverlayOptions() 
       .image(BitmapDescriptorFactory.fromBitmap(mDotMarkerBitmap3)) 
       .position(xDesign, 100)); 
     Animation groundAnimation3 = new RadiusAnimation(groundOverlay3); 
     groundAnimation2.setRepeatCount(Animation.INFINITE); 
     groundAnimation2.setRepeatMode(Animation.RESTART); 
     //  groundAnimation2.setDuration(1100); 
     breadingAnimations.addAnimation(groundAnimation3); 

     mapFragment.getView().startAnimation(breadingAnimations); // start animation 


     mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(xDesign, 15)); 
    } 
+0

Ich versuche, genau die gleiche Animation zu erzielen, wie Sie erwähnten. Ich habe Ihren Code als Referenz verwendet, aber ich habe einige Probleme. Ich sehe die Animation überhaupt nicht. Nicht sicher, was ich falsch mache. – Neha

+0

Ich habe Angst, dass ich nicht mehr für die gleiche Firma arbeite, also habe ich keinen Zugriff mehr auf den Code, den ich benutzt habe. Der Code hier ist die einzige Quelle, die ich habe, um die Animation zu erreichen. Ich erinnere mich, dass es für mich aber funktionierte :) –

+0

ok, keine probs. Vielen Dank :) – Neha