谷歌地图API中的标记GIF类型动画ANDROID [英] GIF type animation for marker in google map api ANDROID

查看:522
本文介绍了谷歌地图API中的标记GIF类型动画ANDROID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要实现GIF动画等标记动画。我得到了两张应该同时闪烁的图像。我没有发现任何可以在android中实现这一点的东西。我试图做的是,创建一个每1秒运行一次的处理程序,并且我正在设置标记的图标。但它不起作用。请指导我正确的方向。



我的代码截至目前如下。

  Handler handler = new Handler(); 
布尔型marker_color_bool = true;

//添加标记并将标记实例发送到marker_animation()方法,其中处理函数被调用。

MarkerOptions marker = new MarkerOptions()
.title(delivery_center_name)
.snippet(This is the+ delivery_center_name +location)
.position(位置)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.red_marker));

google_map.addMarker(marker);

marker_animation(marker);

marker_animation()方法

  private final int ONE_SECONDS = 1000; 
public void marker_animation(final MarkerOptions marker){

handler.postDelayed(new Runnable(){
public void run(){

Log。如果(marker_color_bool == true)
{

marker.icon(R) drawable.green_marker));
marker_color_bool = false;
}
else
{
marker.icon(R.drawable.red_marker));
marker_color_bool = true;
}

handler.postDelayed(this,ONE_SECONDS);
}
},ONE_SECONDS);
}

这种方法不起作用。请帮助我做错了什么。

解决方案


请帮我解释我做错了什么?

您正在修改不再使用的对象。一旦调用 addMarker() MarkerOptions 对象就没有其他意义了,但这是通过您的修改 postDelayed()逻辑。

(顺便说一句,你不需要一个 Handler ,作为 postDelayed()可用于任何查看



addMarker()返回一个标记。您需要通过 setIcon()

$ b来处理 Marker 来影响您的更改。
$ b

另外,由于你的位图没有改变,我建议缓存你的两个 BitmapDescriptor 对象,而不是每次都重新创建它们。 / p>

I want to achieve a marker animation such as GIF animation. I got two images which should be blinking simultaneously. I found nothing which can acheive this in android. I am trying to do is , creating a handler which run every 1 second , and I am trying to set icon for marker. But it doesnt work. Please guide me in right direction.

my code as of now is as follows.

  Handler handler = new Handler();
  Boolean marker_color_bool = true;

//adding marker and sending the marker instance to marker_animation() method where handler is called.

MarkerOptions marker = new MarkerOptions()
                .title(delivery_center_name)
                .snippet("This is the " + delivery_center_name + " location")
                .position(location)
                .icon(BitmapDescriptorFactory.fromResource(R.drawable.red_marker));

        google_map.addMarker(marker);

        marker_animation(marker);

marker_animation() method

 private final int ONE_SECONDS = 1000;
public void marker_animation(final MarkerOptions marker ) {

    handler.postDelayed(new Runnable() {
        public void run() {

            Log.e("running",""+marker_color_bool);

            if(marker_color_bool == true)
            {

                marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.green_marker));
                marker_color_bool = false;
            }
            else
            {
                marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.red_marker));
                marker_color_bool = true;
            }

            handler.postDelayed(this, ONE_SECONDS);
        }
    }, ONE_SECONDS);
}

this approach doesnt work..Please help me what I am doing wrong.

解决方案

Please help me what I am doing wrong

You are modifying an object that is no longer being used. Once addMarker() is called, the MarkerOptions object has no further meaning, yet this is what you are modifying via your postDelayed() logic.

(BTW, you don't need a Handler, as postDelayed() is available on any View)

addMarker() returns a Marker. You will need to work with that Marker to affect your changes, via setIcon().

Also, since your bitmaps are not changing, I suggest caching your two BitmapDescriptor objects, rather than re-creating them on every pass.

这篇关于谷歌地图API中的标记GIF类型动画ANDROID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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