Android custom view realizes the code of imitating the vertical scrolling advertisement bar of store 1

The effect picture shows that the picture is a little stuck. Be patient. The original program is very smooth

Implementation steps:

Implementation principle (coordinate transformation principle): the whole process is based on the increase and exchange of coordinate y. The y value will be increased to Endy, and then the exchange logic will be carried out

Step 1: declare variables

Since store 1 is a two sentence rolling, we also use two sentences to realize it

Step 2: initialize brush, text size and coordinates

Take the first sentence as the standard to make the width and height standard of the control

Step 3: onmeasure() adapts wrap_ Width and height of content

If you have learned how to customize a view, you should be familiar with the following code: adapt to warp_ Template code of content:

Step 4: ondraw() draw two paragraphs of text according to the coordinates (fixed: the bug that flashes when text stops)

Change the speed through the handler

Through the isscroll lock, the handler is controlled to change only once

Always redraw the text of two sentences through invalidate

Step 5: monitor click events (fixed: the click events are disordered)

Rewrite dispatchtouchevent in the custom view to handle click events. This is also the template code:

Step 6: implement click event in activity

Layout file

Source code of the whole class:

The above is the Android custom view introduced to you by Xiaobian, which realizes the code of imitating the vertical scrolling advertisement bar of store 1. 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
分享
二维码
< <上一篇
下一篇>>