动画合集

补间动画分类:

TranslateAnimation(位移动画)
RotateAnimation(旋转动画)
ScaleAnimation(缩放动画)
AlphaAnimation(透明度渐变)
AnimationSet(组合渐变)

1.位移动画

TranslateAnimation animation =new TranslateAnimation(Animation.RELATIVE_TO_SELF,0f, Animation.RELATIVE_TO_SELF,1f,Animation.RELATIVE_TO_SELF,0f, Animation.RELATIVE_TO_SELF,1f);
        animation.setDuration(2000);
        animation.setInterpolator(this, android.R.anim.linear_interpolator);
        img.startAnimation(animation);
        animation.start();

2.旋转动画

RotateAnimation animation = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 0f);
        animation.setDuration(5000);
        animation.setInterpolator(this, android.R.anim.accelerate_interpolator);
        img.startAnimation(animation);
        animation.start();

3.缩放动画

        ValueAnimator animator = ValueAnimator.ofFloat(1.0f, 0.6f, 1.2f, 1.0f, 0.6f, 1.2f, 1.0f);
        animator.setDuration(6000L);//设置缩放时间
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float scale = (Float) animation.getAnimatedValue();
                img.setScaleX(scale);
                img.setScaleY(scale);
            }
        });
        animator.setInterpolator(new LinearInterpolator());
        animator.start();
    }

4.透明动画

                AlphaAnimation animation = new AlphaAnimation(1, 0);
                animation.setDuration(2000);
                animation.setRepeatCount(-1);
                img.startAnimation(animation);
                animation.start();

5.组合渐变




    

    
    
    


    

    
    
    


    

    
    


    

    
    
    

       
       //在MainActivity中的代码
        Animation animation = AnimationUtils.loadAnimation(this, R.anim.anim);
        img.startAnimation(animation);

你可能感兴趣的:(动画合集)