将动画 GIF 叠加在 MapView 上
我一直在绞尽脑汁地试图让这个看似简单的任务发挥作用。 我需要将一个动画 gif 放在地图视图上的叠加层中。
我有以下代码:
AnimationDrawable anim = (AnimationDrawable)getResources().getDrawable(R.drawable.explosion);
但是我现在如何将其弹出到叠加层中并将其扔到地图视图上?
目前,要放置静态图像,我有这样的:
class DrawableIcon extends ItemizedOverlay {
private ArrayList mOverlays = new ArrayList();
public DrawableIcon(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}
@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
@Override
public int size() {
return mOverlays.size();
}
}
然后我这样使用:(gp 是我想要放置图像的地点的地理点)
DrawableIcon image = new DrawableIcon(this.getResources().getDrawable(ResourceID));
image.addOverlay(new OverlayItem(gp, "", ""));
mapOverlays.add(image);
那么我将如何修改此代码,以便当 ResourceID 是一个动画 gif 图像,gif 图像会在地图视图上播放它的动画吗?
提前致谢!
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:
AnimationDrawable anim = (AnimationDrawable)getResources().getDrawable(R.drawable.explosion);
However how do I now pop that in an overlay and throw it over the mapview?
Currently, to put static images I have this:
class DrawableIcon extends ItemizedOverlay {
private ArrayList mOverlays = new ArrayList();
public DrawableIcon(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}
@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
@Override
public int size() {
return mOverlays.size();
}
}
Which I then use as such: (gp is the geopoint of the spot I want to put the image in)
DrawableIcon image = new DrawableIcon(this.getResources().getDrawable(ResourceID));
image.addOverlay(new OverlayItem(gp, "", ""));
mapOverlays.add(image);
So how would I go about modifying this code so that when ResourceID is the ID of an animated gif image, the gif image would play it's animation over the mapview?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要在地图上显示动画,可以使用 MapView 类的 addView 方法。但视图的布局参数必须使用 MapView.LayoutParams 进行初始化。
在这种情况下,当您滚动地图时,视图将自动移动!
它很简单:
将视图添加到 MapView。
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.