View的getDrawingCache为空,解决办法,android界面开发基础

quality = Bitmap.Config.ARGB_8888;

break;

}

} else {

// Optimization for translucent windows

// If the window is translucent, use a 32 bits bitmap to benefit from memcpy()

quality = use32BitCache ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;

}

// Try to cleanup memory

if (bitmap != null) bitmap.recycle();

try {

bitmap = Bitmap.createBitmap(width, height, quality);

bitmap.setDensity(getResources().getDisplayMetrics().densityDpi);

if (autoScale) {

mDrawingCache = bitmap;

} else {

mUnscaledDrawingCache = bitmap;

}

if (opaque && use32BitCache) bitmap.setHasAlpha(false);

} catch (OutOfMemoryError e) {

// If there is not enough memory to create the bitmap cache, just

// ignore the issue as bitmap caches are not required to draw the

// view hierarchy

if (autoScale) {

mDrawingCache = null;

} else {

mUnscaledDrawingCache = null;

}

mCachingFailed = true;

return;

}

clear = drawingCacheBackgroundColor != 0;

}

Canvas canvas;

if (attachInfo != null) {

canvas = attachInfo.mCanvas;

if (canvas == null) {

canvas = new Canvas();

}

canvas.setBitmap(bitmap);

// Temporarily clobber the cached Canvas in case one of our children

// is also using a drawing cache. Without this, the children would

// steal the canvas by attaching their own bitmap to it and bad, bad

// thing would happen (invisible views, corrupted drawings, etc.)

attachInfo.mCanvas = null;

} else {

// This case should hopefully never or seldom happen

canvas = new Canvas(bitmap);

}

if (clear) {

bitmap.eraseColor(drawingCacheBackgroundColor);

}

computeScroll();

final int restoreCount = canvas.save();

if (autoScale && scalingRequired) {

final float scale = attachInfo.mApplicationScale;

canvas.scale(scale, scale);

}

canvas.translate(-mScrollX, -mScrollY);

mPrivateFlags |= DRAWN;

if (mAttachInfo == null || !mAttachInfo.mHardwareAccelerated ||

mLayerType != LAYER_TYPE_NONE) {

mPrivateFlags |= DRAWING_CACHE_VALID;

}

// Fast path for layouts with no backgrounds

if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) {

if (ViewDebug.TRACE_HIERARCHY) {

ViewDebug.trace(this, ViewDebug.HierarchyTraceType.DRAW);

}

mPrivateFlags &= ~DIRTY_MASK;

dispatchDraw(canvas);

} else {

draw(canvas);

}

canvas.restoreToCount(restoreCount);

canvas.setBitmap(null);

if (attachInfo != null) {

// Restore the cached Canvas for our siblings

attachInfo.mCanvas = canvas;

}

}

}

/**

  • Create a snapshot of the view into a bitmap. We should probably make

  • some form of this public, but should think about the API.

*/

Bitmap createSnapshot(Bitmap.Config quality, int backgroundColor, boolean skipChildren) {

int width = mRight - mLeft;

int height = mBottom - mTop;

final AttachInfo attachInfo = mAttachInfo;

final float scale = attachInfo != null ? attachInfo.mApplicationScale : 1.0f;

width = (int) ((width * scale) + 0.5f);

height = (int) ((height * scale) + 0.5f);

Bitmap bitmap = Bitmap.createBitmap(width > 0 ? width : 1, height > 0 ? height : 1, quality);

if (bitmap == null) {

throw new OutOfMemoryError();

}

Resources resources = getResources();

if (resources != null) {

bitmap.setDensity(resources.getDisplayMetrics().densityDpi);

}

Canvas canvas;

if (attachInfo != null) {

canvas = attachInfo.mCanvas;

if (canvas == null) {

canvas = new Canvas();

}

canvas.setBitmap(bitmap);

// Temporarily clobber the cached Canvas in case one of our children

// is also using a drawing cache. Without this, the children would

// steal the canvas by attaching their own bitmap to it and bad, bad

// things would happen (invisible views, corrupted drawings, etc.)

attachInfo.mCanvas = null;

} else {

// This case should hopefully never or seldom happen

canvas = new Canvas(bitmap);

}

if ((backgroundColor & 0xff000000) != 0) {

bitmap.eraseColor(backgroundColor);

}

computeScroll();

final int restoreCount = canvas.save();

canvas.scale(scale, scale);

canvas.translate(-mScrollX, -mScrollY);

// Temporarily remove the dirty mask

int flags = mPrivateFlags;

mPrivateFlags &= ~DIRTY_MASK;

// Fast path for layouts with no backgrounds

if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) {

dispatchDraw(canvas);

} else {

draw(canvas);

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级安卓工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Android移动开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img
img
img
img

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
img

最后

希望本文对你有所启发,有任何面试上的建议也欢迎留言分享给大家。

好了,今天的分享就到这里,如果你对在面试中遇到的问题,或者刚毕业及工作几年迷茫不知道该如何准备面试并突破现状提升自己,对于自己的未来还不够了解不知道给如何规划,可以加一下下面的技术群来看看同行们都是如何突破现状,怎么学习的,来吸收他们的面试以及工作经验完善自己的之后的面试计划及职业规划。

这里放一下资料获取方式:GitHub

好了~如果你看到了这里,觉得文章写得不错就给个赞呗?如果你觉得那里值得改进的,请给我留言。一定会认真查询,修正不足。谢谢。

何准备面试并突破现状提升自己,对于自己的未来还不够了解不知道给如何规划,可以加一下下面的技术群来看看同行们都是如何突破现状,怎么学习的,来吸收他们的面试以及工作经验完善自己的之后的面试计划及职业规划。

这里放一下资料获取方式:GitHub

[外链图片转存中…(img-MCIZmKKK-1711204352927)]

好了~如果你看到了这里,觉得文章写得不错就给个赞呗?如果你觉得那里值得改进的,请给我留言。一定会认真查询,修正不足。谢谢。

[外链图片转存中…(img-H5OrvGZM-1711204352927)]

为什么某些人会一直比你优秀,是因为他本身就很优秀还一直在持续努力变得更优秀,而你是不是还在满足于现状内心在窃喜!希望读到这的您能点个小赞和关注下我,以后还会更新技术干货,谢谢您的支持!

  • 16
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值