I\'ve been pulling my hair out trying to get this seemingly simple task to work. I need to put an animated gif in an overlay on a mapview.
I have the following code:
To display an animation over map you can use addView method of MapView class. But layout params of the view must be initialized with MapView.LayoutParams.
In this case the View will automatically move when you scroll the map!
It is as simple as:
add the view to MapView.
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);
}