将动画 GIF 叠加在 MapView 上

发布于 2024-11-08 19:28:33 字数 1080 浏览 0 评论 0原文

我一直在绞尽脑汁地试图让这个看似简单的任务发挥作用。 我需要将一个动画 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔女人霸气范 2024-11-15 19:28:33

要在地图上显示动画,可以使用 MapView 类的 addView 方法。但视图的布局参数必须使用 MapView.LayoutParams 进行初始化。

在这种情况下,当您滚动地图时,视图将自动移动!

它很简单:

  1. 只需创建一个视图(如 ImageView 或任何其他视图);
  2. 初始化视图布局,创建MapView.LayoutParams并将其传递给setLayoutParams方法;
  3. 将视图添加到 MapView。

    public static void addAnimationToMap(MapView 地图, int AnimationResourceId, GeoPoint geoPoint) {
    
        最终 ImageView 视图 = new ImageView(map.getContext());
        view.setImageResource(animationResourceId);
    
        //发布开始动画,因为如果在活动OnCreate方法中调用start()方法,动画不会开始。
        view.post(new Runnable() {
            @覆盖
            公共无效运行(){
                AnimationDrawable animationDrawable = (AnimationDrawable) view.getDrawable();
                动画Drawable.start();
            }
        });
    
        地图.addView(视图);
    
        MapView.LayoutParamslayoutParams = new MapView.LayoutParams(
            MapView.LayoutParams.WRAP_CONTENT,
            MapView.LayoutParams.WRAP_CONTENT,
            地理点,
            MapView.LayoutParams.BOTTOM_CENTER);
        view.setLayoutParams(layoutParams);
    
    }
    

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:

  1. just create a view (like ImageView or any other View);
  2. initialize the view layout, create and pass MapView.LayoutParams to setLayoutParams method;
  3. 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);
    
    }
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文