I'm trying to move the ball to the canvas. a and b are similar to the x, y coordinates. In any case, from my code I am trying to get different values dynamically. A, b are global variables. But it seems that the "invalidate ()" or screen update occurs only after the end of the full cycle. You know why?. And if I need to build this in another thread, please offer me some simple codes.
private void shootBall(){ while (a>b){ a = getPositionX(); b = getPositionY(); invalidate(); } } }
do it like this and use postInvalidate () instead:
private void shootBall(){ new Thread(new Runnable() { public void run() { while (a>b){ a = getPositionX(); b = getPositionY(); postInvalidate(); } } }).start(); }
edit: , , , invalidate , , , .
, , invalidate() , ( ) . , invalidate ( ) , onDraw(). , / , . , invalidate() ... , .
, - (, , ). , invalidate() . , .
invalidate() onDraw(), : ?
, .
SurfaceView, : http://www.droidnova.com/playing-with-graphics-in-android-part-i,147.html
The user interface cannot be changed from any new thread. You should use invalidate () in the same thread as your view