Can I use AnimationDrawable in an overlay on a MapView?
Asked Answered
P

1

6

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>
Period answered 13/9, 2011 at 19:38 Comment(1)
what you have found is totally brilliant and acceptable but it is an alternative to main solution,there should be someway of doing the animation with overlay class as it is meant to put markers on map.what you are doing is direct calling a render thread on map and draw whatever you want.fine.But what i want is your solution to work with markers.have you found anything regarding that? I am looking for same but there is lot more change for me if i change overlay class with your suggested inflation method.Alexandrina
M
3

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/

Monovalent answered 15/9, 2011 at 9:21 Comment(1)
Updated link: gauntface.co.uk/blog/2010/01/04/mapview-with-widgets-androidHetrick

© 2022 - 2024 — McMap. All rights reserved.