当我尝试在位图画布(包括cardview和imageview)上绘制我的视图时,下载的滑行图像未显示在最终的位图中,我特别在滑行成功侦听器中调用我的方法以确保我的图像被加载到视图中,但是仍然,最终位图中没有显示任何图像(只有带有颜色的cardview)。
这是我将代码加载到imageview中的代码:
View marker = ((LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.mapelement, null);
ImageView markerImage = (ImageView) marker.findViewById(R.id.imageView);
CardView cardView = marker.findViewById(R.id.cardview);
Glide.with(getActivity())
.using(new FirebaseImageLoader())
.load(mStorageRef.child("images").child("profilepicture1"))
.listener(new RequestListener<StorageReference, GlideDrawable>() {
@Override
public boolean onException(Exception e, StorageReference model, Target<GlideDrawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, StorageReference model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
cardView.setCardBackgroundColor(Color.parseColor(somecolor));
LatLng markerlocation = new LatLng(somelat, somelong);
mMap.addMarker(new MarkerOptions().position(markerlocation).
icon(BitmapDescriptorFactory.fromBitmap(
loadBitmapFromView(marker)))).setTitle("new marker");
return true;
}
})
.into(markerImage);
将视图转换为位图:
public static Bitmap loadBitmapFromView(View v) {
v.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
Bitmap b = Bitmap.createBitmap(v.getMeasuredWidth(), v.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
v.draw(c);
return b;
}