问题描述
如果parent
是AppCompatActivity的实例,则一切正常。
如果我将方法签名更改为createRouteBitmapFromLayout(Activity parent,ColorStateList color)
,并从扩展了android.app.Activity
的活动中调用它,那么我会得到一个正确大小的空位图。
回顾一下,唯一改变的是AppCompatActivity =>活动。
private static Bitmap createRouteBitmapFromLayout(AppCompatActivity parent,ColorStateList color) {
View newViewElement = View.inflate(parent,R.layout.icon_node_topo_display,null);
((ImageView) newViewElement.findViewById(R.id.imagePin)).setimageTintList(color);
newViewElement.measure(IconType.poiRouteIcon.measuredWidth,IconType.poiRouteIcon.measuredHeight);
newViewElement.layout(0,newViewElement.getMeasuredWidth(),newViewElement.getMeasuredHeight());
Bitmap bitmap = Bitmap.createBitmap(newViewElement.getMeasuredWidth(),newViewElement.getMeasuredHeight(),Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.setDrawFilter(new PaintFlagsDrawFilter(0,Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG));
Drawable background = newViewElement.getBackground();
if (background != null) {
background.draw(canvas);
}
newViewElement.draw(canvas);
return Bitmap.createScaledBitmap(bitmap,IconType.poiRouteIcon.iconPxWith,IconType.poiRouteIcon.iconPxHeight,true);
}
感谢您的帮助。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)