Two ways to achieve android animation Effects
Animation effects are implemented in two ways. Note: In this example, the animation effects are AlphaAnimation. For other effects, just change the object. 1. Control the addition of java file code and start the animation.
// Add the animation effect AlphaAnimation animation = new AlphaAnimation (0.3f, 1.0f); // set the animation duration. setDuration (2000); // sets the animation listening event animation. setAnimationListener (new AnimationListener () {@ Overridepublic void onAnimationStart (Animation animation) {// The Animation starts listening to events // do something ...} @ Overridepublic void onAnimationRepeat (Animation animation) {}@ Overridepublic void onAnimationEnd (Animation animation) {// listen to the Animation end event // do something ...}}); // start the animation view. startAnimation (animation );
2. load xml file code to start animation alpha_out.xml fade-out effect
Code loading xml:
Attribute:
private Animation anim;private AnimationListener animLis;
Load:
// Initialize the Animation listening event AnimationListeneranimLis = new AnimationListener () {@ Overridepublic void onAnimationStart (Animation arg0) {// The Animation starts listening to events // do something ...} @ Overridepublic void onAnimationRepeat (Animation arg0) {}@ Overridepublic void onAnimationEnd (Animation arg0) {// listen to the Animation end event // do something... TV. setVisibility (View. GONE) ;}}; // load xmlanim = AnimationUtils. loadAnimation (this, R. anim. alpha_out); // set the listening event anim. setAnimationListener (animLis); // start the animation TV. startAnimation (anim );