The method of realizing the effect of imitating heartbeat animation by Android programming _android

Source: Internet
Author: User

The example in this article describes the method of Android programming to achieve the effect of imitation heartbeat animation. Share to everyone for your reference, specific as follows:

button analog heartbeat private void Playheartbeatanimation () {Animationset animationset = new Animationset (true); Animationset.addanimation (New Scaleanimation (1.0f, 1.8f, 1.0f, 1.8f, Animation.relative_to_self, 0.5f, Animation.rela
  Tive_to_self, 0.5f));
  Animationset.addanimation (New Alphaanimation (1.0f, 0.4f));
  Animationset.setduration (200);
  Animationset.setinterpolator (New Accelerateinterpolator ());
  Animationset.setfillafter (TRUE); Animationset.setanimationlistener (New Animationlistener () {@Override public void Onanimationstart (Animation animati ON) {} @Override public void Onanimationrepeat (Animation Animation) {} @Override public void Onanimati
    OnEnd (Animation Animation) {animationset animationset = new Animationset (true); Animationset.addanimation (New Scaleanimation (1.8f, 1.0f, 1.8f, 1.0f, Animation.relative_to_self, 0.5f, Animati On.
    Relative_to_self, 0.5f));
    Animationset.addanimation (New Alphaanimation (0.4f, 1.0f));Animationset.setduration (600);
    Animationset.setinterpolator (New Decelerateinterpolator ());
        Animationset.setfillafter (FALSE);
   Realize the heartbeat of the View Imageview.startanimation (Animationset);
    }
  });
Realize the heartbeat of the View Imageview.startanimation (Animationset);

 }

Because this is a looping animation, you need to open a thread for the implementation of animation, of course, there is another way, is to start another animation at the end of an animation, at the end of another animation can be the animation, this example with a thread.

New Thread () {public
 void run () {while
  (true) {
   try {
    thread.sleep (1000);
   } catch ( Interruptedexception e) {
    //TODO auto-generated catch block
    e.printstacktrace ();
   }
   Runonuithread (New Runnable () {public
    void run () {
     playheartbeatanimation ();}}
   );
  }
 ;
}.start ();

I hope this article will help you with the Android program.

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.