Android implementation of simple clock view

Simplifying the drawing logic through the translation and rotation of canvas is a very useful skill. The following clock view is completed by this method, which saves the trouble of using trigonometric function to calculate coordinates.

The code comments have been detailed, and the more important parts are described below:

Call canvas. Save() at the beginning of drawing to save the original canvas state without any translation or rotation operation. After all drawing work is completed, call canvas.restore (), which can revert to the last saved state (similar to the feeling of entering and leaving the stack).

The translation and rotation of canvas may be abstract and can be imagined as the translation and rotation of coordinate system. Calling canvas.translate (DX, Dy) is equivalent to moving the coordinate origin to the X, Y direction by the distance of DX, dy. calling canvas.rotate (degree) is equivalent to rotating the coordinate system clockwise by degree °.

Decide whether to draw large scale (multiple of 90 °) or small scale according to I value. After drawing one line at a time, rotate the coordinate system clockwise by 30 °, so as to ensure that the coordinates of the scale line drawn each time remain unchanged.

The function is to execute the drawing process of view again after 1000ms (1s) to produce the effect of pointer movement.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>