我想用animatedVectorDrawable作为安卓系统中的地图标记。有办法这样做吗。我尝试的是,我使用BitmapDescriptorFactory类将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);
}
}发布于 2019-01-30 11:12:51
你不能那样做。为了将图像作为标记添加到地图中,您将需要一个位图(png更好)。您可以做的是将向量转换为位图,然后再试一次。
https://stackoverflow.com/questions/50343726
复制相似问题