欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android編程實(shí)現(xiàn)仿心跳動(dòng)畫效果的方法

 更新時(shí)間:2015年11月19日 14:35:12   作者:lee0oo0  
這篇文章主要介紹了Android編程實(shí)現(xiàn)仿心跳動(dòng)畫效果的方法,實(shí)例分析了Android基于線程實(shí)現(xiàn)動(dòng)畫過度效果的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了Android編程實(shí)現(xiàn)仿心跳動(dòng)畫效果的方法。分享給大家供大家參考,具體如下:

// 按鈕模擬心臟跳動(dòng)
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);
        // 實(shí)現(xiàn)心跳的View
    imageView.startAnimation(animationSet);
   }
  });
    // 實(shí)現(xiàn)心跳的View
  imageView.startAnimation(animationSet);
}

由于這是一個(gè)循環(huán)的動(dòng)畫,所以需要開一個(gè)線程來進(jìn)行動(dòng)畫的實(shí)現(xiàn),當(dāng)然還有另外一個(gè)方法,就是在一個(gè)動(dòng)畫結(jié)束開始另一個(gè)動(dòng)畫,在另一個(gè)動(dòng)畫結(jié)束開始這個(gè)動(dòng)畫也可以,這邊示例用的是線程。

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

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論