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.