欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android编程实现仿心跳动画效果的方法

程序员文章站 2023-12-15 10:27:04
本文实例讲述了android编程实现仿心跳动画效果的方法。分享给大家供大家参考,具体如下: // 按钮模拟心脏跳动 private void playheart...

本文实例讲述了android编程实现仿心跳动画效果的方法。分享给大家供大家参考,具体如下:

// 按钮模拟心脏跳动
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.relative_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 animation) {
   }
   @override
   public void onanimationrepeat(animation animation) {
   }
   @override
   public void onanimationend(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,
      animation.relative_to_self, 0.5f));
    animationset.addanimation(new alphaanimation(0.4f, 1.0f));
    animationset.setduration(600);
    animationset.setinterpolator(new decelerateinterpolator());
    animationset.setfillafter(false);
        // 实现心跳的view
    imageview.startanimation(animationset);
   }
  });
    // 实现心跳的view
  imageview.startanimation(animationset);
}

由于这是一个循环的动画,所以需要开一个线程来进行动画的实现,当然还有另外一个方法,就是在一个动画结束开始另一个动画,在另一个动画结束开始这个动画也可以,这边示例用的是线程。

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

希望本文所述对大家android程序设计有所帮助。

上一篇:

下一篇: