Android custom flash page ad countdown view effect

Now there are more and more apps, and we use more and more software every day. But how can app manufacturers achieve revenue and even profit without paying? The answer is to insert advertisements where we have to go to open the software. Of course, in order to take into account the user's feelings, they are generally displayed to the user in the form of countdown, and the user can choose to skip. It may be because of his obsessive-compulsive disorder and always thinking about how to do it, so he tried to share it with everyone and deepen his understanding. The effect is shown in the figure:

1. In order to meet the requirements of product and design, first make several user-defined attributes

1) Inner background 2) color of numbers 3) width of outer ring 4) text size 5) color of outer ring 6) radius of circle

Here, my outer ring color is the same as the text color. The specific custom attributes are as follows:

--------------------------------------------------------------------------------

2. Read custom attributes in the construction method of custom view:

--------------------------------------------------------------------------------

3. Override the onmeasure() method,

The radius is obtained according to the width and height. Why not apply the custom radius? Because the radius obtained from the width and height is the inscribed circle radius of this view, the user-defined radius is only used when the radius cannot be obtained from the width and height

The getviewsize method is as follows:

--------------------------------------------------------------------------------

4. Draw with OnDraw method

1) Draw inner circle

2) When drawing text, calculate the position of the text and keep it centered

3) Draw a ring with a constantly refreshing outer layer

Principle: arc drawing is carried out at intervals from 360 degrees. The angles are 360359 and 1 respectively. Therefore, a poller is required to continuously draw and refresh. Code for drawing arc:

--------------------------------------------------------------------------------

5. Refreshed poller

1) Implementation using rxandroid and lambda

2) Implemented using threads

OK, so our advertisement countdown is completed. Welcome to correct

Attachment: Code of the whole custom view

The above is the countdown view effect of Android custom flash page advertisement introduced by Xiaobian. I hope it can help you. If you have any questions, please leave me a message. 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
分享
二维码
< <上一篇
下一篇>>