将GIF动画在覆盖了图形页面 [英] Put animated GIF in overlay over MapView

查看:119
本文介绍了将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.

我有以下的code:

AnimationDrawable anim = (AnimationDrawable)getResources().getDrawable(R.drawable.explosion);

不过我怎么现在突然,在一个覆盖扔过来的MapView?

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();
    }

}

然后我这样使用:(GP就是我想要把在图像的光斑的GeoPoint)

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);

所以,我怎么会去修改这个code,这样当的ResourceID是动画GIF图像的ID,GIF图像将发挥它的动画结束的MapView?

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?

在此先感谢!

推荐答案

要显示的动画过地图,你可以使用图形页面类addView方法。但视图的布局PARAMS必须MapView.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!

这是简单的:

  1. 只要创建一个视图(如ImageView的或任何其他View);
  2. 初始化视图布局,创造并传递MapView.LayoutParams到setLayoutParams方法;
  3. 添加视图以图形页面。

  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);

}

这篇关于将GIF动画在覆盖了图形页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆