Rendering Inside onDraw(…)

When your application is launched, all of its views are invalid. This means that they have not drawn anything to the screen. To fix this situation, Android calls the top-level View’s draw() method. This causes that view to draw itself, which causes its children to draw themselves. Those children’s children then draw themselves, and so on down the hierarchy. When all the views in the hierarchy have drawn themselves, then the top-level View is no longer invalid.

To hook into this drawing, you override the following View method:

 ​ ​ ​ ​p​r​o​t​e​c​t​e​d​ ​v​o​i​d​ ​o​n​D​r​a​w​(​C​a​n​v​a​s​ ​c​a​n​v​a​s​)​

The call to invalidate() that you make in response to ACTION_MOVE in onTouchEvent(…) makes the BoxDrawingView ...

Get Android Programming: The Big Nerd Ranch Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.