美文网首页
Android动画——位移动画、旋转动画、缩放动画、渐变动画

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

作者: 穿越平行宇宙 | 来源:发表于2019-03-22 09:25 被阅读0次

    属性动画分类:

    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.渐变动画
            //制作透明度的变化值范围
            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();
    

    相关文章

      网友评论

          本文标题:Android动画——位移动画、旋转动画、缩放动画、渐变动画

          本文链接:https://www.haomeiwen.com/subject/jvikvqtx.html