我无法显示从互联网下载的图像作为注释.我正在执行以下代码和毕加索图书馆.但是,如果我使用本地图像,它可以工作.提前感谢任何帮助.
private void createAnnotation(int id,double lat,double lon,String caption,String photoUrl) { SKAnnotation annotation = new SKAnnotation(id); SKCoordinate coordinate = new SKCoordinate(lat,lon); annotation.setLocation(coordinate); annotation.setMininumZoomLevel(5); SKAnnotationView annotationView = new SKAnnotationView(); View customView = (LinearLayout) ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate( R.layout.annotation_photo_and_text,null,false); // If width and height of the view are not power of 2 the actual size of the image will be the next power of 2 of max(width,height). //annotationView.setView(findViewById(R.id.customView)); TextView tvCaption = (TextView) customView.findViewById(R.id.annotation_photo_caption); tvCaption.setText(caption); ImageView ivPhoto = (ImageView) customView.findViewById(R.id.annotation_photo); Picasso.with(getApplicationContext()) .load(photoUrl) .resize(96,96) //.centerCrop() .into(ivPhoto); //ivPhoto.setImageResource(R.drawable.hurricanerain); annotationView.setView(customView); annotation.setAnnotationView(annotationView); mapView.addAnnotation(annotation,SKAnimationSettings.ANIMATION_NONE); }
解决方法
毕加索加载来自互联网的图像异步.尝试将图像下载到注释后再尝试添加.您可以使用目标来监听图像下载完成:
ImageView ivPhoto = (ImageView) customView.findViewById(R.id.annotation_photo); Target target = new Target() { @Override public void onBitmapLoaded(Bitmap bitmap,Picasso.LoadedFrom from) { ivPhoto.setImageBitmap(bitmap); annotationView.setView(customView); annotation.setAnnotationView(annotationView); mapView.addAnnotation(annotation,SKAnimationSettings.ANIMATION_NONE); } @Override public void onBitmapFailed(Drawable errorDrawable) {} @Override public void onPrepareLoad(Drawable placeHolderDrawable) {} }; ivPhoto.setTag(target); Picasso.with(getApplicationContext()) .load(photoUrl) .resize(96,96) .into(target);