在百度地图添加覆盖物附带文字

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 16:45   994   0

本人写在 eoe论坛的文章,http://www.eoeandroid.com/thread-260821-1-1.html

思路:因为百度地图添加覆盖物只能是图片,就是只能添加格式为 Drawable 的图片,而我们需要添加的文字是Textview,不能使用,已经百度查看,Drawable有子类BitmapDrawable,而BitmapDrawable可以由Bitmap生成,Layout 转换成Bitmap是可行的,于是我们的覆盖物既有图片又有文字就是一个Layout,
上代码:
LayoutInflater factory = LayoutInflater.from(this);
View textEntryView = factory.inflate(R.layout.overlay_view, null); 把视图转换成Bitmap 再转换成Drawable
textEntryView.setDrawingCacheEnabled(true);
textEntryView.measure(
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
textEntryView.layout(0, 0, textEntryView.getMeasuredWidth(),
textEntryView.getMeasuredHeight());
textEntryView.buildDrawingCache();
Bitmap newbmp = textEntryView.getDrawingCache();
BitmapDrawable bd =new BitmapDrawable(newbmp);
这个bd 就可以是Drawable格式的覆盖物了

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP