AnimatedVectorDrawable 作为地图标记

AnimatedVectorDrawable as map marker

我想使用 animatedVectorDrawable 作为 Android 中的地图标记。有没有办法做到这一点。 我尝试的是,我使用 BitmapDescriptorFactory class 将 VectorDrawable 转换为位图并且它工作正常,但是当我去转换 AnimatedVectorDrawable 它在地图上没有任何显示

下面是我目前尝试过的代码

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

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