(原创)android加载GIF图片到地图(或者其他图层)中

最近在项目中遇到需要加载动态图片(类似GIF)到地图图层中,Google许久之后找到答案:

1.将GIF图片分解成多个图层,如location_anim0.png,location_anim1.png,location_anim2.png,location_anim3.png...

 然后将上述文件扔进drawable文件夹;新建一个location_anim.xml, 同样放置于drawable文件夹当中,内容如下:

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false" >

<item
android:drawable="@drawable/location_anim0"
android:duration="300"/>
<item
android:drawable="@drawable/location_anim1"
android:duration="300"/>
<item
android:drawable="@drawable/location_anim2"
android:duration="300"/>
<item
android:drawable="@drawable/location_anim3"
android:duration="300"/>

</animation-list>

2.做好上面的准备工作后,接下来写一个生成动态view并且将其加入到Mapview当中的方法:

// 将GIF图加入到map当中

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();
}
});
    //GeoPoint为经纬度
MapView.LayoutParams layoutParams = new MapView.LayoutParams(
MapView.LayoutParams.WRAP_CONTENT,
MapView.LayoutParams.WRAP_CONTENT, geoPoint, 10, 10,
MapView.LayoutParams.CENTER);
view.setLayoutParams(layoutParams);
view.setId(100);
map.addView(view);


}

3.最后在需要添加GIF图的Activity中调用此工具类,就大功告成了:

LocationUtils.addAnimationToMap(mMapView,
R.drawable.location_anim, gPoint);

如果需要动态的删除这个GIF图,只需要findViewById(100),然后removeView就OK。

这个方案适合用来制作比较动感的地图实时定位点。

OVER~


转载于:https://www.cnblogs.com/jaredlam/archive/2012/02/21/2361584.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值