在postInvalidate()或invalidate()调用时,canvas.drawText()无法更新 [英] canvas.drawText() is not able to update when called by postInvalidate() or invalidate()
问题描述
我已将得分作为静态变量在int
我的onDraw()方法中的一段代码:
canvas.drawText(得分为+得分,30,50,油漆);
试试{
主题.sleep(2000);
invalidate();
} catch(InterruptedException e1){
/ / TODO自动生成的捕获块
e1.printStackTrace();
}
一段代码onTouchEvent()方法:
x = event.getX();
y = event.getY();
if(rectangle.contains(x,y)== true)
{
得分++;
postInvalidate();
}
但是当这个if循环为真时我无法更新文字
我做错了什么?
i have declared score as an static variable in int
piece of code in my onDraw() method:
canvas.drawText("score is " + score, 30, 50, paint);
try {
Thread.sleep(2000);
invalidate();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
piece of code in onTouchEvent() method:
x = event.getX();
y = event.getY();
if(rectangle.contains(x, y)==true)
{
score++;
postInvalidate();
}
but when this if loop is true i was not able to update text
what is the mistake i have done?
推荐答案
检查:
Android画布绘制文本和之后的更改文本 [ ^ ]
< a href =http://stackoverflow.com/questions/15496114/drawing-to-canvas-while-in-loop>在循环中绘制画布 [ ^ ]
Check:
Android Canvas Drawing Text and Change Text afterwards[^]
Drawing to canvas in loop[^]
这篇关于在postInvalidate()或invalidate()调用时,canvas.drawText()无法更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!