Android custom view drawing to realize fade animation

An interesting little thing is realized: draw with a custom view, draw lines while drawing, and the lines gradually fade until they disappear. The effect is shown in the following figure:

You can change one by one with attribute animation or gradient fill (shader), but if you want to change a gradient (draw and fade without raising your finger), there is no ready-made API available in Android. So I made one myself.

The basic idea is this:

• record the touch points in the ontouchevent of view, generate line elements one by one, and put them in a list. Configure a paint instance for each lineelement. • Draw line segments in OnDraw. • • transform the alpha value of the paint instance of the lineelement. • Reorganizes the list of segments according to the alpha value

No more, the code:

This example can also add some effects, such as making the lines lighter and thinner at the same time.

At present, there are still some problems. If the line is thick, you can obviously see that there are gaps or cracks between line segments. Who thought of how to optimize it?

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