Android的绘图缓存缓存、Android

2023-09-13 01:02:04 作者:酒醉夜未阑

请解释如何做在Android上的绘图缓存的工作。我实现自定义视图子类。我希望我的图纸由系统缓存。在视图构造函数中,我称之为

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);

然后抽奖(帆布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给我。我的画()不叫既不是来自 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.

仅供参考,通过安卓版本的SDK管理器的某些(不是全部)是View类的资源可用。

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