animations之三interpolator

interpolator里面是五个控制动画动作快慢的参数

AccelerateDecelerateInterpolator,中间加速,两头慢

AccelerateInterpolator:开始慢,然后加速

CycleInterpolator:动画循环播放特定次数,速率改变沿着正弦曲线

DecelerateInterpolator:减速

LinearInterpolator:匀速

三种使用方法

1.使用xml文件

  set中有此属性设置

  <set xmlns:android="http://schemas.android.com/apk/res/android"
 android:interpolator="@android:anim/accelerate_interpolator"
 android:shareInterpolator="true">

 代码中直接使用这个xml文件

   Animation animation = AnimationUtils.loadAnimation(animation.this, R.anim.alpha);
   imageView.startAnimation(animation);

2.为所有动画使用一样的interpolator

   AnimationSet animationSet = new AnimationSet(true);

   animationSet.setInterpolator(new DecelerateInterpolator());
   AlphaAnimation alpha = new AlphaAnimation(1.0f, 0.0f);
   RotateAnimation rotate = new RotateAnimation(0, 360,
   Animation.RELATIVE_TO_SELF, 0.5f,
   Animation.RELATIVE_TO_SELF, 0.5f);
   animationSet.addAnimation(alpha);
   animationSet.addAnimation(rotate);
   animationSet.setDuration(10000);
   animationSet.setStartOffset(500);
   imageView.startAnimation(animationSet);

3.分别为每个动画设置interpolator

   AnimationSet animationSet = new AnimationSet(false);
   AlphaAnimation alpha = new AlphaAnimation(1.0f, 0.0f);
   alpha.setInterpolator(new DecelerateInterpolator());
   RotateAnimation rotate = new RotateAnimation(0, 360,
   Animation.RELATIVE_TO_SELF, 0.5f,
   Animation.RELATIVE_TO_SELF, 0.5f);
   rotate.setInterpolator(new AccelerateInterpolator());
   animationSet.addAnimation(alpha);
   animationSet.addAnimation(rotate);
   animationSet.setDuration(10000);
   animationSet.setStartOffset(500);
   imageView.startAnimation(animationSet);

 

 

代码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值