下面列出了android.animation.ValueAnimator#setStartDelay ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public List<Animator> createAnimation() {
List<Animator> animators = new ArrayList<>();
long[] durations = new long[]{1260, 430, 1010, 730};
long[] delays = new long[]{770, 290, 280, 740};
for (int i = 0; i < 4; i++) {
final int index = i;
ValueAnimator scaleAnim = ValueAnimator.ofFloat(1, 0.4f, 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();
animators.add(scaleAnim);
}
return animators;
}
@Override
public List<Animator> createAnimation() {
List<Animator> animators = new ArrayList<>();
float circleSpacing = 4;
float radius = (getWidth() - circleSpacing * 2) / 6;
int[] delays = new int[]{70, 140, 210};
for (int i = 0; i < 3; i++) {
final int index = i;
ValueAnimator scaleAnim = ValueAnimator.ofFloat(getHeight() / 2, getHeight() / 2 - radius * 2, getHeight() / 2);
scaleAnim.setDuration(600);
scaleAnim.setRepeatCount(-1);
scaleAnim.setStartDelay(delays[i]);
scaleAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
translateYFloats[index] = (float) animation.getAnimatedValue();
postInvalidate();
}
});
scaleAnim.start();
animators.add(scaleAnim);
}
return animators;
}
@Override public void setUpAnimation() {
for (int i = 0; i < numberOfCircle; i++) {
final int index = i;
ValueAnimator fadeAnimator = ValueAnimator.ofFloat(0, 360);
fadeAnimator.setRepeatCount(ValueAnimator.INFINITE);
fadeAnimator.setDuration(1700);
fadeAnimator.setStartDelay((index >= 5 ? index - 5 : index) * 100);
fadeAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override public void onAnimationUpdate(ValueAnimator animation) {
rotates[index] = (float)animation.getAnimatedValue();
if (invalidateListener != null) {
invalidateListener.reDraw();
}
}
});
fadeAnimator.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;
}
public List<Animator> createAnimation() {
List<Animator> animators = new ArrayList<>();
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) {
scaleFloats[index] = (float) animation.getAnimatedValue();
postInvalidate();
}
});
scaleAnim.start();
animators.add(scaleAnim);
}
return animators;
}
@Override
public ArrayList<ValueAnimator> onCreateAnimators() {
ArrayList<ValueAnimator> animators=new ArrayList<>();
float circleSpacing=4;
float radius=(getWidth()-circleSpacing*2)/6;
int[] delays=new int[]{70,140,210};
for (int i = 0; i < 3; i++) {
final int index=i;
ValueAnimator scaleAnim= ValueAnimator.ofFloat(getHeight()/2,getHeight()/2-radius*2,getHeight()/2);
scaleAnim.setDuration(600);
scaleAnim.setRepeatCount(-1);
scaleAnim.setStartDelay(delays[i]);
addUpdateListener(scaleAnim,new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
translateYFloats[index] = (float) animation.getAnimatedValue();
postInvalidate();
}
});
animators.add(scaleAnim);
}
return animators;
}
@Override
public List<Animator> createAnimation() {
List<Animator> animators = new ArrayList<>();
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) {
scaleFloats[index] = (float) animation.getAnimatedValue();
postInvalidate();
}
});
scaleAnim.start();
animators.add(scaleAnim);
}
return animators;
}
@Override
public List<Animator> createAnimation() {
List<Animator> animators = new ArrayList<>();
long[] delays = new long[]{400, 200, 0, 200, 400};
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<>();
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] = (int) animation.getAnimatedValue();
postInvalidate();
}
});
alphaAnim.start();
animators.add(alphaAnim);
}
return animators;
}
public ArrayList<ValueAnimator> createBallJumpAnimators() {
ArrayList<ValueAnimator> animators = new ArrayList<>();
int[] delays = new int[]{70, 140, 210};
for (int i = 0; i < 3; i++) {
final int index = i;
ValueAnimator scaleAnim = ValueAnimator.ofFloat(mTextBottomBorder, mTextBottomBorder - mBallRadius * 2, mTextBottomBorder);
scaleAnim.setDuration(600);
scaleAnim.setRepeatCount(-1);
scaleAnim.setStartDelay(delays[i]);
scaleAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
translateYFloats[index] = (float) animation.getAnimatedValue();
postInvalidate();
}
});
animators.add(scaleAnim);
}
return animators;
}
private void dynamicGap(CompositionAvatarView view) {
ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f);
animator.setDuration(2000);
animator.setStartDelay(1000);
animator.setInterpolator(new AccelerateDecelerateInterpolator());
animator.setRepeatMode(ValueAnimator.REVERSE);
animator.setRepeatCount(ValueAnimator.INFINITE);
animator.addUpdateListener(animation -> view.setGap((Float) animation.getAnimatedValue()));
mGapAnimator = animator;
}
private static @Nullable Animator createLottieAnimator(@Nullable UpdateListener updateListener) {
if (updateListener == null) return null;
final ValueAnimator lottieAnimator = ValueAnimator.ofFloat(0, 1f);
lottieAnimator.setStartDelay(ANIMATION_START_DELAY);
lottieAnimator.setDuration(LOTTIE_ANIMATION_DURATION);
lottieAnimator.addUpdateListener(animation -> updateListener.onUpdate((float) animation.getAnimatedValue()));
return lottieAnimator;
}
public void startAnim() {
RectF startRect = new RectF(targetSize.centerX(), targetSize.centerY(), targetSize.centerX(), targetSize.centerY());
ValueAnimator rectSize = ValueAnimator.ofObject(new RectFEvaluator(), startRect, targetSize);
rectSize.setDuration(animDuration);
rectSize.setInterpolator(new QuintOut());
rectSize.setStartDelay(startDelay);
rectSize.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
drawingRect = (RectF) animation.getAnimatedValue();
invalidate();
}
});
rectSize.start();
}
private void refreshRest() {
ValueAnimator animator = ValueAnimator.ofFloat(mRefreshView.getTranslationY(), mRefreshHideTranslationY);
animator.setStartDelay(60);
animator.setDuration(300).start();
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override public void onAnimationUpdate(ValueAnimator animation) {
if (mRefreshView.getTranslationY() == mRefreshHideTranslationY) {
animation.cancel();
} else {
mRefreshView.setTranslationY((Float) animation.getAnimatedValue());
}
}
});
}
public void animateClipAboveDecreasing(float decreaseTarget, long duration, long delay) {
if (mClipPath == null) return;
ValueAnimator valueAnimator = ValueAnimator.ofFloat(mClipHeightAbove, mClipHeightAbove - decreaseTarget)
.setDuration(duration);
valueAnimator.setStartDelay(delay);
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
mClipHeightAbove = (float) animation.getAnimatedValue();
updateClip();
requestLayout();
}
});
valueAnimator.start();
}
private void startTranslationZAnimation(
View view, MaterialShapeDrawable materialShapeDrawable, float maxTranslationZ) {
ValueAnimator animator = ValueAnimator.ofFloat(0, maxTranslationZ);
animator.setDuration(ANIMATION_DURATION_MILLIS);
animator.setStartDelay(ANIMATION_START_DELAY_MILLIS);
animator.setRepeatMode(ValueAnimator.RESTART);
animator.setRepeatCount(ValueAnimator.INFINITE);
animator.addUpdateListener(
animation ->
setTranslationZ(view, materialShapeDrawable, (float) animation.getAnimatedValue()));
animator.start();
}
private void startTextSizeAnimation(final TextView view, long startDelay, long duration, float startSize, float endSize){
ValueAnimator textSizeAnimator = ValueAnimator.ofFloat(startSize, endSize);
textSizeAnimator.setDuration(duration);
textSizeAnimator.setStartDelay(startDelay);
textSizeAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
view.setTextSize((float) valueAnimator.getAnimatedValue());
}
});
textSizeAnimator.start();
}
private void createBallAnimator(Ball ball, int startDelay) {
ValueAnimator valueAnimator = new ValueAnimator();
valueAnimator.setFloatValues(mMinRadius, mMaxRadius);
valueAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
valueAnimator.setDuration(mDuration);
valueAnimator.addUpdateListener(new BallUpdateListener(ball));
valueAnimator.setRepeatMode(ValueAnimator.REVERSE);
valueAnimator.setRepeatCount(ValueAnimator.INFINITE);
valueAnimator.setStartDelay(startDelay);
mBallAnimators.add(valueAnimator);
valueAnimator.start();
}
public void startAnim() {
RectF startRect = new RectF(targetSize.centerX(), targetSize.centerY(), targetSize.centerX(), targetSize.centerY());
ValueAnimator rectSize = ValueAnimator.ofObject(new RectFEvaluator(), startRect, targetSize);
rectSize.setDuration(animDuration);
rectSize.setInterpolator(new QuintOut());
rectSize.setStartDelay(startDelay);
rectSize.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
drawingRect = (RectF) animation.getAnimatedValue();
invalidate();
}
});
rectSize.start();
}
public void show() {
AndroidUtilities.cancelRunOnUIThread(dismissTunnable);
if (a != null) {
a.removeAllListeners();
a.cancel();
}
if (getMeasuredHeight() == 0 || getMeasuredWidth() == 0) {
showOnMeasure = true;
return;
}
showing = true;
setVisibility(View.VISIBLE);
prepareProgress = 0;
enterValue = 0;
currentStart = start;
currentEnd = end;
startOffsetValue = 1f;
endOffsetValue = 1f;
invalidate();
ValueAnimator prepareAnimation = ValueAnimator.ofFloat(0, 1f);
prepareAnimation.addUpdateListener(animation -> {
prepareProgress = (float) animation.getAnimatedValue();
invalidate();
});
prepareAnimation.setDuration(210);
prepareAnimation.setInterpolator(new DecelerateInterpolator());
ValueAnimator enterAnimation = ValueAnimator.ofFloat(0, 1f);
enterAnimation.addUpdateListener(animation -> {
enterValue = (float) animation.getAnimatedValue();
invalidate();
});
enterAnimation.setStartDelay(600);
enterAnimation.setDuration(250);
ValueAnimator moveStart = ValueAnimator.ofFloat(1f, 0f);
moveStart.setStartDelay(500);
moveStart.addUpdateListener(animation -> {
startOffsetValue = (float) animation.getAnimatedValue();
currentStart = (int) (animateToStart + ((start - animateToStart) * startOffsetValue));
invalidate();
});
moveStart.setInterpolator(CubicBezierInterpolator.EASE_OUT);
moveStart.setDuration(500);
ValueAnimator moveEnd = ValueAnimator.ofFloat(1f, 0f);
moveEnd.setStartDelay(400);
moveEnd.addUpdateListener(animation -> {
endOffsetValue = (float) animation.getAnimatedValue();
currentEnd = animateToEnd + (int) Math.ceil((end - animateToEnd) * endOffsetValue);
invalidate();
});
moveEnd.setInterpolator(CubicBezierInterpolator.EASE_OUT);
moveEnd.setDuration(900);
AnimatorSet set = new AnimatorSet();
set.playSequentially(
prepareAnimation,
enterAnimation,
moveStart,
moveEnd
);
a = set;
a.start();
AndroidUtilities.runOnUIThread(dismissTunnable, 5000);
}