android 属性动画

属性动画的出现,弥补了补间动画的不足之处,补间动画,只是改变了表面上的东西,但是其中属性并未改变,而属性动画相反,改变了表面上的东西,并且也更改了其属性。
属性动画 Animator

  • ValueAnimator 属性的值变了 视觉没变
  • ObjectAnimator 属性、视觉都变了
  • TimeAnimator
    类:ObjectAnimator
    用于操作属性动画的类

代码

//透明度alpha
ObjectAnimator alphaAni = ObjectAnimator.ofFloat(v,"alpha",1,0,1,0);
        alphaAni.setDuration(1000);
        alphaAni.start();

//旋转
 test.setPivotX(0);
 test.setPivotY(y);
 ObjectAnimator animatorr = ObjectAnimator.ofFloat(test, "rotation", 43);
 animatorr.setDuration(1000);
 animatorr.start();

//缩放
        ObjectAnimator scaleAniX = ObjectAnimator.ofFloat(v,"scaleX",1f,1.1f,1f,1.1f,1f);
        scaleAniX.setDuration(1000);
//        scaleAniX.setRepeatCount(-1);
        scaleAniX.setRepeatMode(ValueAnimator.REVERSE);
        scaleAniX.start();
        ObjectAnimator scaleAniY = ObjectAnimator.ofFloat(v,"scaleY",1f,1.1f,1f,1.1f,1f);
        scaleAniY.setDuration(1000);
//        scaleAniY.setRepeatCount(-1);
        scaleAniY.setRepeatMode(ValueAnimator.REVERSE);
        scaleAniY.start();
        //with 同时执行
        //before 前面执行
        //after 后面执行

        //playTogether 同时执行
        //playSequentially 顺序执行
        AnimatorSet aset = new AnimatorSet();
//        aset.playTogether(scaleAniX,scaleAniY);
        aset.play(scaleAniX).with(scaleAniY);
        aset.start();

//移动
ObjectAnimator transAni = ObjectAnimator.ofFloat(v,"translationX",v.getTranslationX()+100);
        transAni.setDuration(1000);
        transAni.start();

test为需要设置动画的控件
setPivotX和setPiovotY为动画的起始点

ObjectAnimator.ofFloat()括号中的参数:
第一个参数,要实现动画的控件id
第二个参数,要实现的动画属性,以下列出6种:

propertyName 详细作用
alpha 实现渐变效果
rotation 实现旋转旋转效果
translationX 实现水平移动效果(左或右移动)
translationY 实现纵向移动效果(向上或者向下移动)
scaleX 实现轴X缩放效果(放大或者缩小)
scaleY 实现轴Y缩放效果(放大或者缩小)

后面为动画的值

你可能感兴趣的:(android 属性动画)