属性动画简单的使用

//透明度起始为1,结束时为0 透明
ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, "alpha", 1f, 0f, 1f);
animator.setDuration(2000);
animator.start();

//360度旋转

ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, "rotation", 0f, 360f, 0f);
animator.setDuration(2000);
animator.start();

//左右移动

ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, "translationX", 0f, -300f, 0f);
animator.setDuration(2000);
animator.start();

//上下移动

ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, "translationY", 0f, -300f, 0f);
animator.setDuration(2000);
animator.start();

//左右缩放

ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, "scaleX", 1f, 2f, 1f);
animator.setDuration(2000);
animator.start();
//上下缩放
ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, "scaleY", 1f, 2f, 1f);
animator.setDuration(2000);
animator.start();
//组合动画
//沿x轴放大ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(imageView, "scaleX", 1f, 2f, 1f);
//沿y轴放大ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(imageView, "scaleY", 1f, 2f, 1f);
//移动ObjectAnimator translationXAnimator = ObjectAnimator.ofFloat(imageView, "translationX", 0f, 200f, 0f);
//透明动画ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, "alpha", 1f, 0f, 1f);
//动画组合的集合
AnimatorSet set = new AnimatorSet();
//同时沿X,Y轴放大,且改变透明度,然后移动
set.play(scaleXAnimator).with(scaleYAnimator).with(animator).before(translationXAnimator);
//都设置3s,也可以为每个单独设置
set.setDuration( 3000);set.start();

//监听事件

//添加监听事件 set.addListener( new Animator.AnimatorListener() { 
  @Override public void onAnimationStart(Animator animation)
  //动画开始的时候调用 
 } 
  @Override public void onAnimationEnd(Animator animation)
  //画结束的时候调用
  @Override public void onAnimationCancel(Animator animation)
  //动画被取消的时候调用
  @Override public void onAnimationRepeat(Animator animation) {
  //动画重复执行的时候调用 } });


作者:带心情去旅行
链接:https://www.jianshu.com/p/d23f58f4368d
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值