Two ways to achieve android animation Effects

Source: Internet
Author: User

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 );



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.