开发者

Am I not doing correctly or understanding double buffering on Android?

I have a function

@Override
public void run() {
    while(running && (!eof)){
        if(surfaceHolder.getSurface().isValid()){
            Canvas canvas = surfaceHolder.lockCanvas();
            paint(canvas);
            surfaceHolder.unlockCanvasAndPost(canvas);  
        }
    }
    thread = null;
}

where paint(canvas) calls a bunch of other functions that draw a graph and text, for example

canvas.drawText("Time="+myRecord.getMyTime(), 100, 100, paint);

The problem I'm having is that the graph and the text, both of which should be constantly changing, don't get erased but instead keep drawing over themselves. Shouldn't my entire canvas get redrawn every time because that's how double buffering works with the lock() and unlock()? Am I not understanding this correctly? How am I开发者_开发知识库 supposed to do this?


You need to clear the Canvas yourself after lockCanvas() using Canvas.drawColor().

This might be relevant too:

The content of the Surface is never preserved between unlockCanvas() and lockCanvas(), for this reason, every pixel within the Surface area must be written. The only exception to this rule is when a dirty rectangle is specified, in which case, non-dirty pixels will be preserved.

Source

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜