Android custom view realizes the score display effect of imitation driving test classic (Collection)

Xiaobian recently found that some cool view effects can be more easily realized by combining custom view and attribute animation.

The effect diagram is as follows:

The knowledge used is:

(1) The path in the custom view is mainly used to draw indicator blocks.

(2) Property animation - valueanimator, and listener for property animation.

(3) Whether to draw the description text content corresponding to the score is determined according to the flag of whether the attribute animation ends.

Implementation steps:

Inheriting from view, get custom properties and initialization operations (initialization brush) in the constructor

The initialization brush is extracted into a function:

Override onsizechanged(), get the width and height of the control, and determine the size of the area to be drawn (the control sets the inner margin by default)

The core drawing code covers the OnDraw () method, and determines whether to draw the text corresponding to the score according to the flag of whether the animation ends.

(1) Draw an arc background and a gray scale background.

(2) Draw the scale, and dynamically change the drawing indication block and the reached progress arc according to the current value curvalue animated by valueanimator, so as to realize the animation effect of moving from 0 to the set value.

(3) Draw fractional text.

(4) At the end of the animation, draw the prompt information corresponding to the final score, which will be displayed only after the animation.

(5) It provides an interface for setting the maximum value externally to determine the final score.

Full code:

The above is the Android custom view introduced by Xiaobian. It realizes the score display effect (Collection) of the imitation driving test dictionary. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

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
分享
二维码
< <上一篇
下一篇>>