欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

属性动画

程序员文章站 2022-03-02 19:38:31
...

透明动画

//做透明动画,参数1:View,代表你要修改那个控件的属性. 参数2:propertyName代表实现什么样子的动画:"alpha",String类型.
                //参数3:float... values,控件修改的参数,new float[]{0.0f, 0.2f, 0.4f, 0.6f, 0.8f, 1.0f}
                ObjectAnimator alpha = ObjectAnimator.ofFloat(imageView, "alpha", new float[]{0.0f, 0.2f, 0.4f, 0.6f, 0.8f, 1.0f});
                //设置动画执行时长.setDuration
                alpha.setDuration(2000);
                //设置动画执行的模式setRepeatMode,参数用ObjectAnimator引用.
                alpha.setRepeatMode(ObjectAnimator.RESTART);
                //设置动画执行的次数.setRepeatCount
                alpha.setRepeatCount(1);
                //使用ObjectAnimator对象开启动画.
                alpha.start();

旋转动画

//做旋转动画,"rotationY".rotationX,rotation  new float[]{90f, 180f, 270f, 360f}
                ObjectAnimator rotationY = ObjectAnimator.ofFloat(imageView, "rotationY", new float[]{90f, 180f, 270f, 360f});
                rotationY.setDuration(2000);
                rotationY.setRepeatMode(ObjectAnimator.RESTART);
                rotationY.setRepeatCount(1);
                rotationY.start();

缩放动画

 //做缩放动画,scaleX,scaleY  new float[]{1f, 2f, 3f, 4f, 5f, 6f,1f}
                ObjectAnimator scaleX = ObjectAnimator.ofFloat(imageView, "scaleX", new float[]{1f, 2f, 3f, 4f, 5f, 6f, 1f});
                scaleX.setDuration(2000);
                scaleX.setRepeatMode(ObjectAnimator.RESTART);
                scaleX.setRepeatCount(1);
                scaleX.start();

平移动画

//做平移动画,translationY,translationX new float[]{10f, 20f, 30f, 40f, 60f, 80f}
                ObjectAnimator translationY = ObjectAnimator.ofFloat(imageView, "translationY", new float[]{10f, 20f, 30f, 40f, 60f, 80f});
                translationY.setDuration(2000);
                translationY.setRepeatMode(ObjectAnimator.RESTART);
                translationY.setRepeatCount(1);
                translationY.start();

动画集合

AnimatorSet set = new AnimatorSet();
                ObjectAnimator oa = ObjectAnimator.ofFloat(imageView, "translationX", new float[]{10f, 20f, 30f, 40f, 60f, 80f});
                oa.setDuration(3000);
                ObjectAnimator oa2 = ObjectAnimator.ofFloat(imageView, "translationY", new float[]{-10f, -20f, -30f, -40f, -60f, -80f});
                oa2.setDuration(3000);
                set.playTogether(oa, oa2);
                set.start();
相关标签: 属性动画