@Override public List<Animator> createAnimation() { List<Animator> animators = new ArrayList<Animator>(); ValueAnimator scaleAnim = ValueAnimator.ofFloat(1, 0.6f, 1); scaleAnim.setDuration(1000); scaleAnim.setRepeatCount(-1); scaleAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { scaleFloat = (Float) animation.getAnimatedValue(); postInvalidate(); } }); scaleAnim.start(); ValueAnimator rotateAnim = ValueAnimator.ofFloat(0, 180, 360); rotateAnim.setDuration(1000); rotateAnim.setRepeatCount(-1); rotateAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { degrees = (Float) animation.getAnimatedValue(); postInvalidate(); } }); rotateAnim.start(); animators.add(scaleAnim); animators.add(rotateAnim); return animators; }
@Override public void createAnimation() { float startX = getWidth() / 6; float startY = getWidth() / 6; for (int i = 0; i < 2; i++) { final int index = i; ValueAnimator translateXAnim = ValueAnimator.ofFloat(startX, getWidth() - startX, startX, getWidth() - startX, startX); if (i == 1) { translateXAnim = ValueAnimator.ofFloat( getWidth() - startX, startX, getWidth() - startX, startX, getWidth() - startX); } ValueAnimator translateYAnim = ValueAnimator.ofFloat(startY, startY, getHeight() - startY, getHeight() - startY, startY); if (i == 1) { translateYAnim = ValueAnimator.ofFloat( getHeight() - startY, getHeight() - startY, startY, startY, getHeight() - startY); } translateXAnim.setDuration(2000); translateXAnim.setInterpolator(new LinearInterpolator()); translateXAnim.setRepeatCount(-1); translateXAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { translateX[index] = (float) animation.getAnimatedValue(); postInvalidate(); } }); translateXAnim.start(); translateYAnim.setDuration(2000); translateYAnim.setInterpolator(new LinearInterpolator()); translateYAnim.setRepeatCount(-1); translateYAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { translateY[index] = (float) animation.getAnimatedValue(); postInvalidate(); } }); translateYAnim.start(); } }
@Override public List<Animator> createAnimation() { List<Animator> animators = new ArrayList<Animator>(); int[] durations = {960, 930, 1190, 1130, 1340, 940, 1200, 820, 1190}; int[] delays = {360, 400, 680, 410, 710, -150, -120, 10, 320}; for (int i = 0; i < 9; i++) { final int index = i; ValueAnimator alphaAnim = ValueAnimator.ofInt(255, 168, 255); alphaAnim.setDuration(durations[i]); alphaAnim.setRepeatCount(-1); alphaAnim.setStartDelay(delays[i]); alphaAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { alphas[index] = (Integer) animation.getAnimatedValue(); postInvalidate(); } }); alphaAnim.start(); animators.add(alphaAnim); } return animators; }
/** * @param anim The animator, must not be null * @param arrayAnimator Incoming typed array for Animator's attributes. * @param arrayObjectAnimator Incoming typed array for Object Animator's attributes. */ private static void parseAnimatorFromTypeArray( ValueAnimator anim, TypedArray arrayAnimator, TypedArray arrayObjectAnimator) { long duration = arrayAnimator.getInt(R.styleable.Animator_android_duration, 300); long startDelay = arrayAnimator.getInt(R.styleable.Animator_android_startOffset, 0); int valueType = arrayAnimator.getInt(R.styleable.Animator_vc_valueType, 0); TypeEvaluator evaluator = null; // Must be a path animator by the time I reach here if (valueType == VALUE_TYPE_PATH) { evaluator = setupAnimatorForPath(anim, arrayAnimator); } else { throw new IllegalArgumentException("target is not a pathType target"); } anim.setDuration(duration); anim.setStartDelay(startDelay); if (arrayAnimator.hasValue(R.styleable.Animator_android_repeatCount)) { anim.setRepeatCount(arrayAnimator.getInt(R.styleable.Animator_android_repeatCount, 0)); } if (arrayAnimator.hasValue(R.styleable.Animator_android_repeatMode)) { anim.setRepeatMode( arrayAnimator.getInt(R.styleable.Animator_android_repeatMode, ValueAnimator.RESTART)); } if (evaluator != null) { anim.setEvaluator(evaluator); } if (arrayObjectAnimator != null) { setupObjectAnimator(anim, arrayObjectAnimator); } }
@Override public void createAnimation() { ValueAnimator scaleAnim = ValueAnimator.ofFloat(1, 0.3f, 1); scaleAnim.setDuration(1000); scaleAnim.setRepeatCount(-1); scaleAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { scaleFloat1 = (float) animation.getAnimatedValue(); postInvalidate(); } }); scaleAnim.start(); ValueAnimator scaleAnim2 = ValueAnimator.ofFloat(1, 0.6f, 1); scaleAnim2.setDuration(1000); scaleAnim2.setRepeatCount(-1); scaleAnim2.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { scaleFloat2 = (float) animation.getAnimatedValue(); postInvalidate(); } }); scaleAnim2.start(); ValueAnimator rotateAnim = ValueAnimator.ofFloat(0, 180, 360); rotateAnim.setDuration(1000); rotateAnim.setRepeatCount(-1); rotateAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { degrees = (float) animation.getAnimatedValue(); postInvalidate(); } }); rotateAnim.start(); }
@Override public void createAnimation() { long[] delays = new long[] {0, 200, 400}; for (int i = 0; i < 3; i++) { final int index = i; ValueAnimator scaleAnim = ValueAnimator.ofFloat(0, 1); scaleAnim.setInterpolator(new LinearInterpolator()); scaleAnim.setDuration(1000); scaleAnim.setRepeatCount(-1); scaleAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { scaleFloats[index] = (float) animation.getAnimatedValue(); postInvalidate(); } }); scaleAnim.setStartDelay(delays[i]); scaleAnim.start(); ValueAnimator alphaAnim = ValueAnimator.ofInt(0, 255); scaleAnim.setInterpolator(new LinearInterpolator()); alphaAnim.setDuration(1000); alphaAnim.setRepeatCount(-1); alphaAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { alphaInts[index] = (int) animation.getAnimatedValue(); postInvalidate(); } }); scaleAnim.setStartDelay(delays[i]); alphaAnim.start(); } }
@Override public void createAnimation() { int[] durations = {720, 1020, 1280, 1420, 1450, 1180, 870, 1450, 1060}; int[] delays = {-60, 250, -170, 480, 310, 30, 460, 780, 450}; for (int i = 0; i < 9; i++) { final int index = i; ValueAnimator scaleAnim = ValueAnimator.ofFloat(1, 0.5f, 1); scaleAnim.setDuration(durations[i]); scaleAnim.setRepeatCount(-1); scaleAnim.setStartDelay(delays[i]); scaleAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { scaleFloats[index] = (float) animation.getAnimatedValue(); postInvalidate(); } }); scaleAnim.start(); ValueAnimator alphaAnim = ValueAnimator.ofInt(255, 210, 122, 255); alphaAnim.setDuration(durations[i]); alphaAnim.setRepeatCount(-1); alphaAnim.setStartDelay(delays[i]); alphaAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { alphas[index] = (int) animation.getAnimatedValue(); postInvalidate(); } }); alphaAnim.start(); } }
@Override public void createAnimation() { int[] delays = new int[] {120, 240, 360}; for (int i = 0; i < 3; i++) { final int index = i; ValueAnimator scaleAnim = ValueAnimator.ofFloat(1, 0.3f, 1); scaleAnim.setDuration(750); scaleAnim.setRepeatCount(-1); // 循环 scaleAnim.setStartDelay(delays[i]); scaleAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { // 每次值value值变化的时候 重设对应 位置圆的scale值 scaleFloats[index] = (float) animation.getAnimatedValue(); postInvalidate(); // 通知重绘 } }); scaleAnim.start(); } }
@Override public List<Animator> createAnimation() { List<Animator> animators = new ArrayList<>(); long[] delays = new long[] {100, 200, 300, 400, 500}; for (int i = 0; i < 5; i++) { final int index = i; ValueAnimator scaleAnim = ValueAnimator.ofFloat(1, 0.4f, 1); scaleAnim.setDuration(1000); scaleAnim.setRepeatCount(-1); scaleAnim.setStartDelay(delays[i]); scaleAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { scaleYFloats[index] = (float) animation.getAnimatedValue(); postInvalidate(); } }); scaleAnim.start(); animators.add(scaleAnim); } return animators; }
@Override public List<Animator> createAnimation() { List<Animator> animators = new ArrayList<>(); float startT = getWidth() / 11; ValueAnimator translationAnim = ValueAnimator.ofFloat(getWidth() - startT, getWidth() / 2); translationAnim.setDuration(650); translationAnim.setInterpolator(new LinearInterpolator()); translationAnim.setRepeatCount(-1); translationAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { translateX = (float) animation.getAnimatedValue(); postInvalidate(); } }); translationAnim.start(); ValueAnimator alphaAnim = ValueAnimator.ofInt(255, 122); alphaAnim.setDuration(650); alphaAnim.setRepeatCount(-1); alphaAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { alpha = (int) animation.getAnimatedValue(); postInvalidate(); } }); alphaAnim.start(); ValueAnimator rotateAnim1 = ValueAnimator.ofFloat(0, 45, 0); rotateAnim1.setDuration(650); rotateAnim1.setRepeatCount(-1); rotateAnim1.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { degrees1 = (float) animation.getAnimatedValue(); postInvalidate(); } }); rotateAnim1.start(); ValueAnimator rotateAnim2 = ValueAnimator.ofFloat(0, -45, 0); rotateAnim2.setDuration(650); rotateAnim2.setRepeatCount(-1); rotateAnim2.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { degrees2 = (float) animation.getAnimatedValue(); postInvalidate(); } }); rotateAnim2.start(); animators.add(translationAnim); animators.add(alphaAnim); animators.add(rotateAnim1); animators.add(rotateAnim2); return animators; }