animation 之动画时间的控制

来源:互联网 发布:淘宝售后怎么赚钱 编辑:程序博客网 时间:2024/06/01 08:05
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

上一篇:animation 之xml控制

下一篇:animations 动画图片的播放

相关热门文章
  • 欢迎时间的旅行在ChinaUnix博...
  • 天天挂机手游
  • 成功人生的十堂课
  • 【新闻】加拿大推出快速移民通...
  • 西游神魔决手游
  • Android之开发环境搭建
  • Android自定义View的实现...
  • AndroidManifest.xml配置文件...
  • Android源码调试方法详解...
  • 不用vs和cygwin!Eclipse+cdt...
  • 请问Linux默认shell的是什么 ...
  • 谁能够帮我解决LINUX 2.6 10...
  • 现在的博客积分不会更新了吗?...
  • shell怎么读取网页内容...
  • ssh等待连接的超时问题...
给主人留下些什么吧!~~