首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AnimatedVectorDrawable作为地图标记

AnimatedVectorDrawable作为地图标记
EN

Stack Overflow用户
提问于 2018-05-15 06:36:38
回答 1查看 310关注 0票数 1

我想用animatedVectorDrawable作为安卓系统中的地图标记。有办法这样做吗。我尝试的是,我使用BitmapDescriptorFactory类将VectorDrawable转换为位图,它工作得很好,但是当我去转换AnimatedVectorDrawable时,它在地图上什么也没有显示。

下面是我迄今为止尝试过的代码

代码语言:javascript
复制
   .
   .
   .
    MarkerOptions marker1 = new MarkerOptions();
    marker1.icon( getBitmapDescriptor(R.drawable.setpickuplocationdrawable));
    marker1.position(pickuplatlng);
    marker1.title("Marker at place1");
    googleMap.addMarker(marker1);
  }




private BitmapDescriptor getBitmapDescriptor(int id) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        AnimatedVectorDrawable vectorDrawable = (AnimatedVectorDrawable) getDrawable(id);

        int h = vectorDrawable.getIntrinsicHeight();
        int w = vectorDrawable.getIntrinsicWidth();

        vectorDrawable.setBounds(0, 0, w, h);

        Bitmap bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bm);
        vectorDrawable.draw(canvas);

        return BitmapDescriptorFactory.fromBitmap(bm);

    } else {
        return BitmapDescriptorFactory.fromResource(id);
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-01-30 11:12:51

你不能那样做。为了将图像作为标记添加到地图中,您将需要一个位图(png更好)。您可以做的是将向量转换为位图,然后再试一次。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50343726

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档