Android 属性动画ObjectAnimator使用demo,组合动画

//第一个参数:指定执行动画的控件,第二个参数:指定控件的属性,第三个参数是可变长参数
public static ObjectAnimator ofFloat(Object target, String propertyName, float... values) 

动画过程监听

animator2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
    @Override
    public void onAnimationUpdate(ValueAnimator valueAnimator) {
        float value = (float) valueAnimator.getAnimatedValue();
        Log.i("lgq",":ssss====="+value);//动画过程监听
    }
});

动画状态监听

animator2.addListener(new Animator.AnimatorListener() {
    @Override
    public void onAnimationStart(Animator animator) {
        Log.i("lgq",":ssss===onAnimationStart=111=");
    }

    @Override
    public void onAnimationEnd(Animator animator) {
        Log.i("lgq",":ssss===onAnimationEnd==222");
        animator2.setAutoCancel(false);
    }

    @Override
    public void onAnimationCancel(Animator animator) {
        Log.i("lgq",":ssss===onAnimationCancel=333=");
        animator.cancel();
    }

    @Override
    public void onAnimationRepeat(Animator animator) {
        Log.i("lgq",":ssss===onAnimationRepeat=444=");
    }
});

动画暂停

animator.pause();

动画重新开始

animator.resume();

动画重复次数

animator2.setRepeatCount(1);

组合动画方法:

AnimatorSet set = new AnimatorSet();
set.play(animator).with(animator3).with(animator2);
set.start();
//透明度动画
ObjectAnimator animator = ObjectAnimator.ofFloat(view,"alpha",1,0,1);  
animator.setDuration(2000);  
animator.start(); 

//旋转动画:围绕x轴旋转
ObjectAnimator animator = ObjectAnimator.ofFloat(tv,"rotationX",0,270,0);  
animator.setDuration(2000);  
animator.start();

//旋转动画:围绕y轴旋转
ObjectAnimator animator = ObjectAnimator.ofFloat(tv,"rotationY",0,180,0);  
animator.setDuration(2000);  
animator.start();

//旋转动画:围绕z轴旋转
ObjectAnimator animator = ObjectAnimator.ofFloat(tv,"rotation",0,270,0);  
animator.setDuration(2000);  
animator.start();  

//平移动画:在x轴上平移
ObjectAnimator animator = ObjectAnimator.ofFloat(tv, "translationX", 0, 200, -200,0);  
animator.setDuration(2000);  
animator.start(); 

//平移动画:在y轴上平移
ObjectAnimator animator = ObjectAnimator.ofFloat(tv, "translationY", 0, 200, -100,0);  
animator.setDuration(2000);  
animator.start(); 

//缩放动画:在x轴缩放
ObjectAnimator animator = ObjectAnimator.ofFloat(tv, "scaleX", 0, 3, 1);  
animator.setDuration(2000);  
animator.start();

//缩放动画:在y轴上缩放
ObjectAnimator animator = ObjectAnimator.ofFloat(tv, "scaleY", 0, 3, 1);  
animator.setDuration(2000);  
animator.start(); 

你可能感兴趣的:(移动开发)