到目前为止,我一直在使用可绘制对象来填充地图上的标记。现在我想知道如果我可以将自定义图像视图显示为地图中的标记,那会很酷。
直到现在我都这样做
itemized= new Itemazide(drawable, mContext);
我想实现类似的目标
我可能有点晚了,但我会为面临/正在面临类似问题的其他人发布解决方案。因此,基本上您要做的(至少对于您正在寻求的解决方案,即强加在类似盒子的背景上的自定义图像)是借助画布将自定义图像强加在背景框上。使用此实现,您可以有效地从画布创建 BitmapDrawable,然后将其指定为“Overlay”/“ItemizedOverlay”的标记。
另外,请不要为每个覆盖层创建一个 ImageView,因为如果您必须同时处理数千个此类 ImageView,这将完全破坏您的内存/您的应用程序。相反,使用可以在构建期间分配给覆盖层的 BitmapDrawables,并且不会像 ImageView 那样消耗足够的内存。
public BitmapDrawable imageOnDrawable(int drawableBackground, Bitmap customImage)
{
//The following line is optional but I'd advise you to minimize the size of
//the size of the bitmap (using a thumbnail) in order to improve draw
//performance of the overlays (especially if you are creating a lot of overlays).
Bitmap customImageThumbnail = ThumbnailUtils.extractThumbnail(
customImage, 100, 100);
Bitmap bm = BitmapFactory.decodeResource(getResources(), drawableId);
bm = Bitmap.createScaledBitmap(bm, 112, 120, false);
Canvas canvas = new Canvas(bm);
canvas.drawBitmap(bm, 0, 0, null);
// The 6,6 in the below line refer to the offset of the customImage/Thumbnail
// from the top-left corner of the background box (or whatever you want to use
// as your background)
canvas.drawBitmap(customImageThumbnail, 6, 6, null);
return new BitmapDrawable(bm);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)