由网友(改变是痛苦,不改变是受苦)分享简介:会有人请尽量向我解释为什么Would anyone please try to explain to me whypublic void addView(View child) {child.setDrawingCacheEnabled(true);child.setWillNotCacheDrawing(fals...
会有人请尽量向我解释为什么
Would anyone please try to explain to me why
public void addView(View child) {
child.setDrawingCacheEnabled(true);
child.setWillNotCacheDrawing(false);
child.setWillNotDraw(false);
child.buildDrawingCache();
if(child.getDrawingCache() == null) { //TODO Make this work!
Log.w("View", "View child's drawing cache is null");
}
setImageBitmap(child.getDrawingCache()); //TODO MAKE THIS WORK!!!
}
始终记录了绘图缓存为空,并设置位为空?
ALWAYS logs that the drawing cache is null, and sets the bitmap to null?
我一定要实际绘制视图的缓存设置过吗?
Do I have to actually draw the view before the cache is set?
谢谢!
推荐答案
我也有这个问题,并发现了这样的回答:
I was having this problem also and found this answer:
v.setDrawingCacheEnabled(true);
// this is the important code :)
// Without it the view will have a dimension of 0,0 and the bitmap will be null
v.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
v.buildDrawingCache(true);
Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
v.setDrawingCacheEnabled(false); // clear drawing cache
相关推荐
最新文章