本人写在 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格式的覆盖物了 |