我使用32x32和64x64(视网膜)作为相同的图标。当我尝试使用SKAnnotationView显示我的图标时,它会加载双倍大小(128x128)。清除注释并再次添加后,大小恢复正常(64x64)。
请找到下面的代码,我按照示例项目代码:
SKAnnotation annotation = new SKAnnotation();
annotation.setUniqueID(-1);
annotation.setLocation(new SKCoordinate(longitude.doubleValue(), latitude.doubleValue()));
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
SKAnnotationView annotationView = new SKAnnotationView();
if (metrics.densityDpi < DisplayMetrics.DENSITY_HIGH) {
annotationView.setDrawableResourceId(R.drawable.ic_annotation);
annotation.setOffset(new SKScreenPoint(16, 16));
annotationView.setWidth(32);
annotationView.setHeight(32);
annotation.setImageSize(32);
} else {
annotationView.setDrawableResourceId(R.drawable.ic_annotation_retina);
annotation.setOffset(new SKScreenPoint(32, 32));
annotationView.setWidth(64);
annotationView.setHeight(64);
annotation.setImageSize(64);
}
annotation.setAnnotationView(annotationView);
mapView.addAnnotation(annotation, SKAnimationSettings.ANIMATION_NONE);
答案 0 :(得分:1)
可能为时已晚,但您可以尝试在
添加注释@Override
public void onSurfaceCreated() {
}
callback.
这是我的代码:
public class OfflineMapFragment extends BaseFragment implements SKMapSurfaceListener {
private void addFilteredAnnotations(){
SKAnnotation annotation = new SKAnnotation();
annotation.setUniqueID(15);
annotation.setLocation(new SKCoordinate(Double.parseDouble(lat,long);
annotation.setMininumZoomLevel(5);
annotation.setOffset(new SKScreenPoint(128, 128));
SKAnnotationView annotationView = new SKAnnotationView();
annotationView.setDrawableResourceId(R.drawable.map_icon);
annotationView.setWidth(128);
annotationView.setHeight(128);
annotation.setAnnotationView(annotationView);
mapView.addAnnotation(annotation, SKAnimationSettings.ANIMATION_NONE);
}
@Override
public void onSurfaceCreated() {
addAnnotation();
}
}