Android 绘图缓存 [英] Android drawing cache

查看:25
本文介绍了Android 绘图缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请解释绘图缓存在 Android 中是如何工作的.我正在实现一个自定义的 View 子类.我希望我的绘图被系统缓存.在视图构造函数中,我调用

Please explain how does the drawing cache work in Android. I'm implementing a custom View subclass. I want my drawing to be cached by the system. In the View constructor, I call

setDrawingCacheEnabled(true);

然后在画布(Canvas c)中,我做:

Then in the draw(Canvas c), I do:

    Bitmap cac = getDrawingCache();
    if(cac != null)
    {
        c.drawBitmap(cac, 0, 0, new Paint());
        return;
    }

然而 getDrawingCache() 向我返回 null.我的 draw() 既不是从 setDrawingCacheEnabled() 调用,也不是从 getDrawingCache() 调用.请问,我做错了什么?

Yet the getDrawingCache() returns null to me. My draw() is not called neither from setDrawingCacheEnabled(), nor from getDrawingCache(). Please, what am I doing wrong?

推荐答案

绘图缓存大小有硬限制,可通过 ViewConfiguration 类使用.我的视图大于缓存允许的大小.

There's a hard limit on drawing cache size, available via the ViewConfiguration class.. My view is larger than allowed for caching.

仅供参考,View 类的源可通过 SDK 管理器获得,适用于某些(并非所有)Android 版本.

FYI, the sources of the View class are available via the SDK Manager for some (not all) Android versions.

这篇关于Android 绘图缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆