问题描述
我想要实现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);
}
这种方法不起作用。请帮助我做错了什么。
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!