animation 之动画时间的控制

Q群: 241359063 更精彩,欢迎共同走向创业学习之旅。
原创:kylin_zeng  http://blog.chinaunix.net/uid/23795897.html在此感谢mars 老师的帮助。转载请注明原创出处,尊重他人的劳动成果。

1、Interpolator定义了动画变化的速率,有如下几种:
 1.1 AccelerateDecelerateInterpolator:在动画开始以及结束的地方速率改变比较慢,中间加速。
 1.2 AccelerateInterpolator:在动画开始的地方速率改变比较慢,然后加速。
 1.3 
DecelerateInterpolator: 减速。
 1.4 CycleInterpolator: 动画循环播放特定的次数,速率改变沿着正弦曲线。
 1.5 LinearInterpolator:动画以均匀的速率
改变。


点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <set xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:interpolator="@android:anim/accelerate_interpolator"   //加快动作
  4.     android:shareInterpolator="true">           //这里的true表示下面的两个动作都使用同一个interpolator,
  5.    // 2. 如果使用android:shareInterpolator="false" 那么就要为后面两个分别定义不同的动作。

  6.         
  7.     <alpha
  8.         // 2. android:interpolator="@android:anim/decelerate_interpolator"
  9.         android:fromAlpha="1.0"
  10.         android:toAlpha="0.0"
  11.         android:startOffset="500"
  12.         android:duration="2000" />

  13.     <rotate 
  14.        // 2. android:interpolator="@android:anim/accelerate_interpolator"
  15.          android:fromDegrees="0"
  16.         android:toDegrees="360"
  17.         android:pivotX="50%"
  18.         android:pivotY="50%"
  19.         android:duration="2000" />
  20. </set>

函数的调用:

点击(此处)折叠或打开

  1. package mars.animation04;

  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.view.View;
  5. import android.view.View.OnClickListener;
  6. import android.view.animation.AccelerateInterpolator;
  7. import android.view.animation.AlphaAnimation;
  8. import android.view.animation.Animation;
  9. import android.view.animation.AnimationSet;
  10. import android.view.animation.DecelerateInterpolator;
  11. import android.view.animation.RotateAnimation;
  12. import android.widget.Button;
  13. import android.widget.ImageView;

  14. public class MainActivity extends Activity {
  15.     private Button button = null;
  16.     private ImageView imageView = null;

  17.     @Override
  18.     public void onCreate(Bundle savedInstanceState) {
  19.         super.onCreate(savedInstanceState);
  20.         setContentView(R.layout.main);
  21.         imageView = (ImageView) findViewById(R.id.imageViewId);
  22.         button = (Button) findViewById(R.id.scaleButtonId);
  23.         button.setOnClickListener(new AnimationButtonListener());
  24.     }

  25.     private class AnimationButtonListener implements OnClickListener {

  26.         @Override
  27.         public void onClick(View v) {
  28.             /**
  29.              * Animation animation =
  30.              * AnimationUtils.loadAnimation(MainActivity.this, R.anim.alpha);
  31.              * imageView.startAnimation(animation);
  32.              */



  33.             // 声明一个AnimationSet对象
  34.             AnimationSet animationSet = new AnimationSet(false);  //这里如果设置成false 就要单独为每一个添加Interpolator.
  35.             AlphaAnimation alpha = new AlphaAnimation(1.0f, 0.0f);
  36.             alpha.setInterpolator(new DecelerateInterpolator());    //添加

  1.             RotateAnimation rotate = new RotateAnimation(0, 360,
  2.                     Animation.RELATIVE_TO_SELF, 0.5f,
  3.                     Animation.RELATIVE_TO_SELF, 0.5f);
  4.             rotate.setInterpolator(new AccelerateInterpolator());   // 添加

  5.             animationSet.addAnimation(alpha);
  6.             animationSet.addAnimation(rotate);
  7.             animationSet.setDuration(2000);
  8.             animationSet.setStartOffset(500);
  9.             imageView.startAnimation(animationSet);
  10.         }

  11.     }
  12. }

14_animations04.rar

<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
阅读(35) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值