Optimize View to Drawable Conversion in OSMDroid
The code above can be optimized by using a more efficient method to convert the view into a drawable. Instead of creating a bitmap and drawing the view onto it, we can use the 'ViewUtils' class provided by the OSMDroid library to directly convert the view into a drawable:
View view = LayoutInflater.from(getContext()).inflate(R.layout.map_item, null, false);
Drawable drawable = ViewUtils.convertToDrawable(view);
OverlayItem item = new OverlayItem("", "", point);
item.setMarker(drawable);
CustomMarker trafficMarker = new CustomMarker(items,listener,map_view.getResourceProxy());
This method will use less memory and be faster than the previous method.
原文地址: https://www.cveoy.top/t/topic/oU9o 著作权归作者所有。请勿转载和采集!