View animations, only view can be used.
After android3.0, the property is animated.
Valueanimation can record the process of a property change, so his object is anything.
So the real purpose of valueanimation is to make a series of value-change functions based on setinterpolator for a certain value of object.
While Valueanimation has a Animatorupdatelistener callback to each 10ms interval, the feedback changes with time values.
The specific code is as follows:
PackageCom.joyfulmath.animatatorsamples;ImportAndroid.animation.ValueAnimator;ImportAndroid.animation.ValueAnimator.AnimatorUpdateListener;ImportAndroid.content.Context;ImportAndroid.graphics.Canvas;ImportAndroid.graphics.Paint;Importandroid.graphics.Paint.Align;ImportAndroid.graphics.Paint.FontMetrics;ImportAndroid.util.AttributeSet;ImportAndroid.util.Log;ImportAndroid.view.View;ImportAndroid.view.animation.BounceInterpolator; Public classValueanimationviewextendsView {Private Static FinalString TAG = "Valueanimationview"; PrivateContext Mcontext =NULL; PrivatePaint Mpaint =NULL; Private floatMX = 0; floattopy = 0; PrivateValueanimator Mvalueanimator =NULL; PublicValueanimationview (Context context) { This(Context,NULL); } PublicValueanimationview (Context context, AttributeSet attrs) { This(context, Attrs, 0); } PublicValueanimationview (context context, AttributeSet attrs,intDefstyle) { Super(context, attrs, Defstyle); LOG.D (TAG,"Valueanimationview"); Mcontext=context; } @Overrideprotected voidOnDraw (canvas canvas) {Super. OnDraw (canvas); LOG.D (TAG,"Ondraw:mx\t" +MX); Canvas.drawcolor (0xffffff00); Canvas.save (); Canvas.translate (0, 0); Canvas.drawtext (TAG, MX, MX-topy, Mpaint); Canvas.restore (); } @Overrideprotected voidOnattachedtowindow () {Super. Onattachedtowindow (); LOG.D (TAG,"Onattachedtowindow"); Mpaint=NewPaint (); Mpaint.settextsize (18); Mpaint.settextalign (Align.left); Mpaint.setcolor (0xffff0000); Mpaint.setantialias (true); FontMetrics FontMetrics=Mpaint.getfontmetrics (); Topy=Fontmetrics.top; floatAscenty =fontmetrics.ascent; floatDescenty =fontmetrics.descent; floatBottomy =Fontmetrics.bottom; LOG.D (TAG,"Onattachedtowindow fontmetrics topy:" +topy+ "\ t ascenty:" + ascenty + "\ t descenty:" +Descenty+ "\ t bottomy:" +bottomy); } @Overrideprotected voidOndetachedfromwindow () {Super. Ondetachedfromwindow (); } Public voidCreateanimator () {if(Mvalueanimator = =NULL) {Mvalueanimator= Valueanimator.offloat (0.0f, 50.0f); Mvalueanimator.setduration (1000); Mvalueanimator.setinterpolator (Newbounceinterpolator ()); Mvalueanimator.addupdatelistener (NewAnimatorupdatelistener () {@Override Public voidonanimationupdate (valueanimator animation) {MX=(Float) animation.getanimatedvalue (); Invalidate (); } }); } } Public voidStartvalueamimator () {log.d (TAG,"Startvalueamimator"); Createanimator (); Mvalueanimator.start (); }}
The code above is a custom view that implements the basics of animation.
The key is to get the properties of the Objcet animation every time OnDraw.
And the trigger condition is:
Mvalueanimator.addupdatelistener (new Animatorupdatelistener () { @Override public void onanimationupdate (valueanimator animation) { = (Float) Animation.getanimatedvalue (); invalidate ();//Trigger OnDraw } ); }
So the key to Valueobjcet is to change the properties of the object during the animation to determine how the animation will be implemented by this change.
Animation of Android (3)