Recent projects, the use of ProgressBar. Think of to use the effect of Android5.0, it is readily implemented.
:
The approximate idea: 1. The circle is drawn through the canvas 2. The animation of the circle is controlled by animator.
Code: 1. Drawing the code for a circle is very easy. @Overrideprotected void OnDraw (canvas canvas) {Super.ondraw (canvas);Canvas.drawarc (ARCRECTF, StartAngle + Incrementangele, SweepAngle, False, Arcpaint);if (Animatorset = = NULL | |!animatorset.isrunning ()) {Startanimation ();}}
by Canvas.draw ARC to draw startangle is to draw the beginning of the angle by adding incrementangle this variable is to better do animation control.
2. Animation Control Code: (This is the most important code) private void Startanimation () {if (animatorset! = null && animatorset.isrunning ()) {Animatorset.cancel (); Cancel Animation}Animatorset = new Animatorset (); Set up a collection of animationsAnimatorset set = Circuanimator (); Create a animatorset that performs a circle of animationsAnimatorset.play (set);Animatorset.addlistener (New Animatorlistener () {Private Boolean iscancel = false;@Overridepublic void Onanimationstart (Animator animation) {}@Overridepublic void Onanimationrepeat (Animator animation) {}@Overridepublic void Onanimationend (Animator animation) {if (!iscancel) {Startanimation (); Keep Looping the animation}}@Overridepublic void Onanimationcancel (Animator animation) {Iscancel = true;}}) ;Animatorset.start ();}The default animation timeprivate int defult_duration = 660;/*** Looping animations*/Private Animatorset Circuanimator () {Small Circle to Big circleValueanimator HoldAnimator1 = valueanimator.offloat (Incrementangele + defult_min_angle, Incrementangele + 115f);Holdanimator1.addupdatelistener (New Animatorupdatelistener () {@Overridepublic void Onanimationupdate (Valueanimator animation) {Incrementangele = (float) animation.getanimatedvalue ();}}) ;Holdanimator1.setduration (defult_duration);Holdanimator1.setinterpolator (New Linearinterpolator ());Valueanimator expandanimator = Valueanimator.offloat (Defult_min_angle, Defult_max_angle);Expandanimator.addupdatelistener (New Animatorupdatelistener () {@Overridepublic void Onanimationupdate (Valueanimator animation) {SweepAngle = (float) animation.getanimatedvalue ();Incrementangele-= SweepAngle;Invalidate ();}}) ;Expandanimator.setduration (defult_duration);Expandanimator.setinterpolator (New Decelerateinterpolator (2));From the big circle to the small circleValueanimator holdanimator = Valueanimator.offloat (startangle, startangle + 115f);Holdanimator.addupdatelistener (New Animatorupdatelistener () {@Overridepublic void Onanimationupdate (Valueanimator animation) {StartAngle = (float) animation.getanimatedvalue ();}});Holdanimator.setduration (defult_duration);Holdanimator.setinterpolator (New Linearinterpolator ());Valueanimator narrowanimator = Valueanimator.offloat (Defult_max_angle, Defult_min_angle);Narrowanimator.addupdatelistener (New Animatorupdatelistener () {@Overridepublic void Onanimationupdate (Valueanimator animation) {SweepAngle = (float) animation.getanimatedvalue ();Invalidate ();}}) ;Narrowanimator.setduration (defult_duration);Narrowanimator.setinterpolator (New Decelerateinterpolator (2));Animatorset set = new Animatorset ();Set.play (HoldAnimator1). with (Expandanimator);Set.play (Holdanimator). with (Narrowanimator). After (HoldAnimator1);return set;}
Ok.
The realization of the idea is mainly animator animation use, very easy way, to be able to practice a animator use. There's no difficulty.
Network Disk source code:Http://pan.baidu.com/s/1dD71XlR
GitHub Address: Https://github.com/flyme2012/EastTrain
Blog Park Address: http://www.cnblogs.com/flyme2012/p/8ec2c75d44f1896aec817ca441aa5b7c.html
Android own definition of 5.0 style ProgressBar