Android custom water ripple animation layout example code

Without much to say, let's see the effect first:

Hi senior search Preview

This is the search preview of senior hi. You can download this app here to see more effects:

http://www.wandoujia.com/apps/com.superlity.hiqianbei

LSearchView

This is an MD style search box, which integrates ripple animation and loading during search. It is very easy to use. If you also need such a search control, you might as well try it: https://github.com/onlynight/LSearchView

RippleEverywhere

Photos of girlfriend:

Photos of girlfriend:

This is a water ripple animation support library. Due to its use, it only supports Android version 4.0 or above. https://github.com/onlynight/RippleEverywhere

Implementation principle

Use attribute animation to complete the implementation of the animation. Since Android 2.3 is not the mainstream model, it is only compatible with systems above 4.0.

For attribute animation, if you still don't know about children's shoes, you can take a look at this article by Hongyang God:

http://www.jb51.net/article/82668.htm

In my opinion, attribute animation is actually similar to a timer. The so-called timer is another thread for timing independent of the main thread. This thread will notify you whenever you reach the set time; Attribute animation is not just another thread. Its ability to operate mainline UI element attributes indicates that thread synchronization has been done inside it.

Basic principles

Let's first look at the key codes:

These two methods are used to save and restore the drawing state. Save the last status before drawing; Restore the previous state after drawing; And so on until running becomes false, the middle process is the process of animation.

Path #addcircle() and canvas #clippath()

Addcircle is used to draw a circle on the path; Clippath draws the cut path (only the area within the path is drawn, and other areas are not drawn).

This section is the key to the dynamic effect of animation. First, there must be a value that changes over time. Every time this value changes, we need to follow the new interface to let the view redraw and call the OnDraw method. We can't call the OnDraw method manually. The invalid provided by the system will force the view to redraw and then call the OnDraw method.

The above is all the key principles of this animation. Let's have a complete source code:

The above is the Android custom water ripple animation layout example code introduced by Xiaobian. 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
分享
二维码
< <上一篇
下一篇>>