Android custom View to achieve Alipay effect

This article introduces how to customize the view with attribute animation to achieve the following effects

The implementation idea is quite simple:

First look at the part that draws the translucent circle

You can see that all the attributes are set on the brush, and then directly call the canvas drawCircle () method to draw a translucent circle. Finally, call invalidate () method to refresh View. We must rewrite the onDraw () method of the parent class. Otherwise, custom view can not be effective. We set up a flag bit isSpreadFlag, which is used to mark whether the diffusion animation is completed.

Then let's implement two animation effects

Spread animation on Click

Very simple, is to change the scale value to 1.8 times

Spread recycle animation when not clicked

Similar to the previous animation, the startoffset parameter can be used to control the running order of animation. For example, Android: startoffset = "1000" means that the animation with this attribute is delayed by 1 second

Then there is the part of using threads to execute animation and logic

Animation part when not clicked

After initializing clickcircleview, add the view to the parent layout, then load the animation and set the loop execution, and finally refresh the view in the child thread with postinvalidate()

Animation when clicked

Hide without clicking animation, initialize ClickCircleView, add the view to List and add it to the parent layout, then load the animation and add isSpreadFlag tags at the end of the animation. Finally, call invalidate () to refresh view and open the thread.

Thread part

Traverse the list, remove the view marked with isspreadflag from the list and parent layout, and refresh the view. Finally, judge that if the list is empty, the animation when it is not clicked will be displayed

Finally, remember to remove the thread in ondestroy()

Using a custom view with attribute animation to achieve this effect has high coupling, but this method is more fluent than using a custom view completely. Most of this method is implemented by referring to the code on other people's blogs, but if it is only used without summarizing, it will not become your own knowledge. Therefore, with this blog.

Reference: Android implements several ideas and methods of Alipay.

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