Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use AnimationDrawable in an overlay on a MapView?

I have created an AnimationDrawable in XML, and it works fine. But on moving the drawable into a MapView as an overlay marker (replacing a static drawable that works fine), the animation stubbornly refuses to play. I've moved the call to start() to a button, for testing, and even when pressed several seconds after the MapView has displayed, the animation doesn't start. I'm seeing nothing in logcat. I know start() needs calling after all the windows are set up, but this seems to be a separate issue.

Are AnimationDrawables compatible with MapView?

Is there something special I need to do to make one work in a MapView?

Have you ever successfully had one work in a MapView?

Solution

Using Matt's solution (below) I added the AnimationDrawable by putting the ImageView inside the MapView's layers, rather than using an overlay.

public void showAnimatedMarker(GeoPoint point) {
    LinearLayout v = (LinearLayout) View.inflate(context, R.layout.markerlayout, null);
    ImageView marker = (ImageView) v.findViewById(R.id.marker);
    AnimationDrawable markerImage = (AnimationDrawable)marker.getDrawable();
    this.addView(v, 0, new MapView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, point, MapView.LayoutParams.BOTTOM_CENTER));
    markerImage.start();
}

And then markerlayout.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >
    <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/marker"
            android:src="@drawable/my_animation_drawable"
    />
</LinearLayout>
like image 759
Ollie C Avatar asked Sep 13 '11 19:09

Ollie C


1 Answers

This is untested with animations, but may be of some use.

I had issues with adding widgets to the MapView, but found the addView method. Try adding the AnimationDrawable through this method, it may change how it is treated by the MapView and hence animate correctly:

Have a look here for a tiny example: http://www.gauntface.co.uk/pages/blog/2010/01/04/mapview-with-widgets-android/

like image 191
Matt Gaunt Avatar answered Oct 27 '22 19:10

Matt Gaunt