我是否做得不正确或不理解 Android 上的双缓冲?
我有一个函数
@Override
public void run() {
while(running && (!eof)){
if(surfaceHolder.getSurface().isValid()){
Canvas canvas = surfaceHolder.lockCanvas();
paint(canvas);
surfaceHolder.unlockCanvasAndPost(canvas);
}
}
thread = null;
}
,其中 Paint(canvas) 调用一堆其他函数来绘制图形和文本,例如,
canvas.drawText("Time="+myRecord.getMyTime(), 100, 100, paint);
我遇到的问题是图形和文本,两者都应该不断变化,而不是被抹掉了,而是继续在自己身上画画。我的整个画布不应该每次都重新绘制吗,因为这就是双缓冲与lock()和unlock()一起工作的方式?我对此理解不正确吗?我该怎么做?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在 lockCanvas() 之后使用 Canvas.drawColor() 自行清除 Canvas。
这也可能相关:
来源
You need to clear the Canvas yourself after lockCanvas() using Canvas.drawColor().
This might be relevant too:
Source