PropertyAnimation

来源:互联网 发布:python微信公众号开发 编辑:程序博客网 时间:2024/06/06 13:19


  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()前调用