Android动画——位移动画、旋转动画、缩放动画、渐变动画

2019-03-22  本文已影响0人  穿越平行宇宙

属性动画分类:

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

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();
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();
        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();
        //制作透明度的变化值范围
        ValueAnimator ob = ValueAnimator.ofFloat(1.0f,0.0f);
        
        //设置运行的时间
        ob.setDuration(5000);
        
        //设置监听
        ob.addUpdateListener(new AnimatorUpdateListener() {
            
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                // TODO Auto-generated method stub
                float value = (Float) animation.getAnimatedValue();
                //给TextView中设置模糊值
                tv.setAlpha(value);
            }
        });
        //开始动画
        ob.start();
上一篇下一篇

猜你喜欢

热点阅读