PropertyAnimation


  ImageView img = (ImageView) findViewById(R.id.img);

  //渐变
   ObjectAnimator objectAnimator=ObjectAnimator.ofFloat(img,"alpha",0f,1f);
  objectAnimator.setRepeatCount(-1);  //一直重复
  objectAnimator.setDuration(5000);   //时间
  objectAnimator.start();            //启动


  //旋转  (2大于1,顺时针旋转;2小于1,逆时针旋转。)
  ObjectAnimator objectAnimator=ObjectAnimator.ofFloat(img,"rotation",0f,360f,360f,0f);
  objectAnimator.setRepeatCount(-1);
  objectAnimator.setDuration(5000);
  objectAnimator.start();

//平移 (translationX:2大于1,向右移动,反之向左移动;translationY:2大于1,向下移动,反之向上移动)
  ObjectAnimator objectAnimator=ObjectAnimator.ofFloat(img,"translationX",0f,200f);
  objectAnimator.setDuration(50000);
  objectAnimator.setRepeatCount(-1);
  objectAnimator.start();

//缩放(后面的参数表示倍数,1f表示原来的大小)
 ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(img, "scaleX", 1f, 2f);
  objectAnimator.setDuration(50000);
  objectAnimator.setRepeatCount(-1);
  objectAnimator.start();


 //混合
  ObjectAnimator alpha=ObjectAnimator.ofFloat(img,"alpha",0f,1f);
  ObjectAnimator rotation=ObjectAnimator.ofFloat(img,"rotation",0f,360f,360f,0f);
  ObjectAnimator translationX=ObjectAnimator.ofFloat(img,"translationX",0f,200f);
  ObjectAnimator scaleX = ObjectAnimator.ofFloat(img, "scaleX", 1f, 2f);
  AnimatorSet set = new AnimatorSet();
  //同时渐变和旋转,且平移,然后缩放
  set.play(alpha).with(rotation).with(translationX).before(scaleX);
  set.setDuration(3000);
  set.start();

  // 也可以设置延迟执行
  // animator.setStartDelay(1000);//延迟1000ms后执行,需要在start()前调用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值