下面列出了android.animation.AnimatorSet#setStartDelay ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void animateStar(final View view, int delay) {
ObjectAnimator alpha = ObjectAnimator.ofFloat(view, "alpha", 0, 1f);
alpha.setDuration(100);
ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 0, 1f);
ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 0, 1f);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(alpha, scaleX, scaleY);
animatorSet.setInterpolator(new BounceInterpolator());
animatorSet.setStartDelay(delay);
animatorSet.setDuration(600);
view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
animatorSet.start();
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
Music.showStar();
}
}, delay);
}
private void setHighlighted(boolean value) {
AnimatorSet animatorSet = new AnimatorSet();
if (value) {
animatorSet.playTogether(
ObjectAnimator.ofFloat(this, "scaleX", 1.06f),
ObjectAnimator.ofFloat(this, "scaleY", 1.06f));
} else {
animatorSet.playTogether(
ObjectAnimator.ofFloat(this, "scaleX", 1.0f),
ObjectAnimator.ofFloat(this, "scaleY", 1.0f));
animatorSet.setStartDelay(40);
}
animatorSet.setDuration(120);
animatorSet.setInterpolator(interpolator);
animatorSet.start();
}
private void startAnimationForWaitSecond() {
for (int i = 0; i < this.pathViewArray.length; i++) {
if (VERSION.SDK_INT >= MSG_CONSUME_FINISH) {
AnimatorSet animatorSet = new AnimatorSet();
ObjectAnimator ofFloat = ObjectAnimator.ofFloat(this.pathViewArray[i], "scaleX", 1.0f, 1.1f);
ObjectAnimator ofFloat2 = ObjectAnimator.ofFloat(this.pathViewArray[i], "scaleY", 1.0f, 1.1f);
animatorSet.playTogether(ofFloat, ofFloat2);
animatorSet.setDuration(300);
ofFloat.setRepeatMode(2);
ofFloat.setRepeatCount(1);
ofFloat2.setRepeatMode(2);
ofFloat2.setRepeatCount(1);
if (i == 1) {
animatorSet.setStartDelay(200);
} else if (i == 2) {
animatorSet.setStartDelay(400);
} else if (i == 3) {
animatorSet.setStartDelay(600);
}
animatorSet.start();
}
}
}
private void setHighlighted(boolean value) {
AnimatorSet animatorSet = new AnimatorSet();
if (value) {
animatorSet.playTogether(
ObjectAnimator.ofFloat(this, View.SCALE_X, 1.06f),
ObjectAnimator.ofFloat(this, View.SCALE_Y, 1.06f));
} else {
animatorSet.playTogether(
ObjectAnimator.ofFloat(this, View.SCALE_X, 1.0f),
ObjectAnimator.ofFloat(this, View.SCALE_Y, 1.0f));
animatorSet.setStartDelay(40);
}
animatorSet.setDuration(120);
animatorSet.setInterpolator(interpolator);
animatorSet.start();
}
/**
* Animate the change in progress of this view
*
* @param end The value to set it to, between 0-100, if -1, there is no bar for null value, otherwise
* a circle will be animated.
* @param duration The the time to run the animation over,
*/
public void animateProgress(int end, int duration, int delay) {
mProgress = end;
ViewGroup parent = (ViewGroup) getParent();
int heightToReach = (parent.getMeasuredHeight() * end) / 102;
int initialHeight = (int) mBarWidth;
heightToReach = (heightToReach < initialHeight) ? initialHeight : heightToReach;
if (end == -1) {
heightToReach = 0;
}
setVisibility(View.INVISIBLE);
setPivotY(heightToReach);
setMinimumHeight(heightToReach);
AnimatorSet set = new AnimatorSet();
setVisibility(VISIBLE);
set.playTogether(Glider.glide(Skill.BounceEaseOut, duration, ObjectAnimator.ofFloat(this, "scaleY", 0, 1)));
set.setDuration(duration);
set.setStartDelay(delay);
set = addListenersToSet(set);
set.start();
}
public void slideForward() {
View movingFragmentView = mFirstFragment.getView();
PropertyValuesHolder rotateX = PropertyValuesHolder.ofFloat("rotationX", 40f);
PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1f);
ObjectAnimator movingFragmentAnimator = ObjectAnimator.ofPropertyValuesHolder(movingFragmentView, rotateX, scaleX, scaleY, alpha);
ObjectAnimator movingFragmentRotator = ObjectAnimator.ofFloat(movingFragmentView, "rotationX", 0);
movingFragmentRotator.setStartDelay(mContext.getResources().getInteger(R.integer.half_slide_up_down_duration));
AnimatorSet s = new AnimatorSet();
s.playTogether(movingFragmentAnimator, movingFragmentRotator);
s.setStartDelay(mContext.getResources().getInteger(R.integer.slide_up_down_duration));
s.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mIsAnimating = false;
mDidSlideOut = true;
}
});
s.start();
((Activity) this.mContext).getFragmentManager().removeOnBackStackChangedListener(this);
}
private void setHighlighted(boolean value) {
AnimatorSet animatorSet = new AnimatorSet();
if (value) {
animatorSet.playTogether(
ObjectAnimator.ofFloat(this, "scaleX", 1.06f),
ObjectAnimator.ofFloat(this, "scaleY", 1.06f));
} else {
animatorSet.playTogether(
ObjectAnimator.ofFloat(this, "scaleX", 1.0f),
ObjectAnimator.ofFloat(this, "scaleY", 1.0f));
animatorSet.setStartDelay(40);
}
animatorSet.setDuration(120);
animatorSet.setInterpolator(interpolator);
animatorSet.start();
}
/**
* The animation to run on the items being removed
*
* @param removed
* An ArrayList of <code>FreeFlowItems</code> removed
* @return The AnimatorSet of the removed objects
*/
protected AnimatorSet getItemsRemovedAnimation(List<FreeFlowItem> removed) {
AnimatorSet disappearingSet = new AnimatorSet();
ArrayList<Animator> fades = new ArrayList<Animator>();
for (FreeFlowItem proxy : removed) {
fades.add(ObjectAnimator.ofFloat(proxy.view, "alpha", 0));
}
disappearingSet.setDuration(oldCellsRemovalAnimationDuration);
disappearingSet.setStartDelay(oldCellsRemovalAnimationStartDelay);
if (animateIndividualCellsSequentially)
disappearingSet.playSequentially(fades);
else
disappearingSet.playTogether(fades);
return disappearingSet;
}
/**
* Animates given View.
*
* @param view the View that should be animated.
*/
private void animateView(final int position, @NonNull final View view, @NonNull final Animator[] animators) {
if (mAnimationStartMillis == -1) {
mAnimationStartMillis = SystemClock.uptimeMillis();
}
ViewCompat.setAlpha(view, 0);
AnimatorSet set = new AnimatorSet();
set.playTogether(animators);
set.setStartDelay(calculateAnimationDelay(position));
set.setDuration(mAnimationDurationMillis);
set.start();
mAnimators.put(view.hashCode(), set);
}
public void setRipple(boolean b) {
rippleSet = b;
if(height > width){
supportPixle = height;
}else{
supportPixle = width;
}
if(rippleSet){
Set = new AnimatorSet();
Set.setStartDelay(0);
mBitmapPaint = new Paint();
mBitmapPaint.setAntiAlias(true);
mBitmapPaint.setColor(0xFFFFFFFF);
}else{
if(Set != null) {
Set.cancel();
Set.setStartDelay(0);
Set = null;
}
mBitmapPaint = null;
}
}
protected Animator pulse() {
LOGI(TAG, "pulse()");
final float scaleFactor = 1.075f;
final int duration = Resources.getSystem().getInteger(android.R.integer.config_shortAnimTime);
ObjectAnimator scaleX = ObjectAnimator.ofFloat(root, View.SCALE_X, scaleFactor, 1.0f);
ObjectAnimator scaleY = ObjectAnimator.ofFloat(root, View.SCALE_Y, scaleFactor, 1.0f);
final AnimatorSet scaleAnim = new AnimatorSet();
scaleAnim.play(scaleX).with(scaleY);
scaleAnim.setDuration(duration);
scaleAnim.setStartDelay(duration / 4);
scaleAnim.setInterpolator(new AccelerateInterpolator());
root.setHasTransientState(true);
hasPulsed = true;
return scaleAnim;
}
protected AnimatorSet createAnimator(View bar, View handle, boolean showFlag) {
ObjectAnimator barAnimator = ObjectAnimator.ofFloat(bar, TRANSLATION_X, showFlag ? 0 : bar.getWidth());
AnimatorSet animator = new AnimatorSet();
if (handleAlwaysVisible) {
animator.play(barAnimator);
} else {
ObjectAnimator handleAnimator = ObjectAnimator.ofFloat(handle, TRANSLATION_X, showFlag ? 0 : handle.getWidth());
animator.playTogether(barAnimator, handleAnimator);
}
animator.setDuration(durationInMillis);
if (!showFlag) {
animator.setStartDelay(delayInMillis);
}
return animator;
}
private void showRetry(){
if(retryAnim!=null)
retryAnim.cancel();
endBtn.setEnabled(false);
retrying=true;
cancelBtn.setVisibility(View.VISIBLE);
cancelBtn.setAlpha(0);
AnimatorSet set=new AnimatorSet();
ObjectAnimator colorAnim;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
colorAnim = ObjectAnimator.ofArgb(endBtnBg, "color", 0xFFe61e44, 0xFF45bc4d);
} else {
colorAnim = ObjectAnimator.ofInt(endBtnBg, "color", 0xFFe61e44, 0xFF45bc4d);
colorAnim.setEvaluator(new ArgbEvaluator());
}
set.playTogether(
ObjectAnimator.ofFloat(cancelBtn, "alpha", 0, 1),
ObjectAnimator.ofFloat(endBtn, "translationX", 0, content.getWidth()/2-AndroidUtilities.dp(52)-endBtn.getWidth()/2),
colorAnim,
ObjectAnimator.ofFloat(endBtnIcon, "rotation", 0, -135)//,
//ObjectAnimator.ofFloat(spkToggle, "alpha", 0),
//ObjectAnimator.ofFloat(micToggle, "alpha", 0),
//ObjectAnimator.ofFloat(chatBtn, "alpha", 0)
);
set.setStartDelay(200);
set.setDuration(300);
set.setInterpolator(CubicBezierInterpolator.DEFAULT);
set.addListener(new AnimatorListenerAdapter(){
@Override
public void onAnimationEnd(Animator animation){
//bottomButtons.setVisibility(View.GONE);
retryAnim=null;
endBtn.setEnabled(true);
}
});
retryAnim=set;
set.start();
}
private void animateBounds() {
List<Animator> newChildAnimators = new ArrayList<Animator>();
List<Animator> boundsAnimators = new ArrayList<Animator>();
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
ChildBounds bounds = getChildBounds(child);
// No start bounds, this is a new child in the container
if (bounds.start.isEmpty()) {
newChildAnimators.add(prepareNewChildAnimator(child));
continue;
}
Animator boundsAnimator = prepareBoundsAnimator(child, bounds);
if (boundsAnimator != null) {
boundsAnimators.add(boundsAnimator);
}
}
AnimatorSet boundsAnimSet = new AnimatorSet();
boundsAnimSet.playTogether(boundsAnimators);
AnimatorSet newChildAnimSet = new AnimatorSet();
newChildAnimSet.setStartDelay(2000);
newChildAnimSet.playTogether(newChildAnimators);
// It's not really safe to animate the bounds of a view without suppressing
// mid-air layout requests. Android's Transition framework supresses re-layout
// on the scene root while the transition is running with a private API
// i.e. ViewGroup.supressLayout(boolean).
AnimatorSet finalSet = new AnimatorSet();
finalSet.play(boundsAnimSet).before(newChildAnimSet);
finalSet.start();
}
private void showRetry() {
if (retryAnim != null)
retryAnim.cancel();
endBtn.setEnabled(false);
retrying = true;
cancelBtn.setVisibility(View.VISIBLE);
cancelBtn.setAlpha(0);
AnimatorSet set = new AnimatorSet();
ObjectAnimator colorAnim;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
colorAnim = ObjectAnimator.ofArgb(endBtnBg, "color", 0xFFe61e44, 0xFF45bc4d);
} else {
colorAnim = ObjectAnimator.ofInt(endBtnBg, "color", 0xFFe61e44, 0xFF45bc4d);
colorAnim.setEvaluator(new ArgbEvaluator());
}
set.playTogether(
ObjectAnimator.ofFloat(cancelBtn, View.ALPHA, 0, 1),
ObjectAnimator.ofFloat(endBtn, View.TRANSLATION_X, 0, content.getWidth() / 2 - AndroidUtilities.dp(52) - endBtn.getWidth() / 2),
colorAnim,
ObjectAnimator.ofFloat(endBtnIcon, View.ROTATION, 0, -135)//,
//ObjectAnimator.ofFloat(spkToggle, View.ALPHA, 0),
//ObjectAnimator.ofFloat(micToggle, View.ALPHA, 0),
//ObjectAnimator.ofFloat(chatBtn, View.ALPHA, 0)
);
set.setStartDelay(200);
set.setDuration(300);
set.setInterpolator(CubicBezierInterpolator.DEFAULT);
set.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
//bottomButtons.setVisibility(View.GONE);
retryAnim = null;
endBtn.setEnabled(true);
}
});
retryAnim = set;
set.start();
}
@Override
protected boolean onCustomOpenAnimation() {
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(
ObjectAnimator.ofFloat(this, ATTACH_ALERT_PROGRESS, 0.0f, 400.0f));
animatorSet.setDuration(400);
animatorSet.setStartDelay(20);
animatorSet.start();
return false;
}
private void animateV(final View theView, int offsetX, int offsetY) {
float randomScale = 1.2f + (float) (Math.random() * 3.0f);
float randomScaleBack = .9f + (float) (Math.random() * .8f);
ObjectAnimator scaleXDown = ObjectAnimator.ofFloat(theView, "scaleX", randomScale);
ObjectAnimator scaleYDown = ObjectAnimator.ofFloat(theView, "scaleY", randomScale);
ObjectAnimator scaleXBack = ObjectAnimator.ofFloat(theView, "scaleX", randomScaleBack);
ObjectAnimator scaleYBack = ObjectAnimator.ofFloat(theView, "scaleY", randomScaleBack);
float alphav = .7f + (float) (Math.random() * .3f);
ObjectAnimator alpha = ObjectAnimator.ofFloat(theView, "alpha", alphav);
long startDelay = (long) (Math.random() * 2000);
AnimatorSet bouncer = new AnimatorSet();
bouncer.setInterpolator(new AnticipateOvershootInterpolator());
bouncer.setStartDelay(startDelay);
bouncer.play(scaleXDown).with(scaleYDown).with(alpha);
bouncer.play(scaleXBack).with(scaleYBack);
bouncer.play(scaleXBack).after(scaleXDown);
ObjectAnimator transitionX = ObjectAnimator.ofFloat(theView, "translationX", mDisplaySize.x / 2);
ObjectAnimator transitionY = ObjectAnimator.ofFloat(theView, "translationY", mDisplaySize.y + 100);
AnimatorSet moveOffSet = new AnimatorSet();
moveOffSet.setStartDelay(2000);
moveOffSet.setDuration(200);
moveOffSet.setInterpolator(new AnticipateOvershootInterpolator());
moveOffSet.play(transitionX).with(transitionY);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.play(moveOffSet).after(bouncer);
animatorSet.start();
}
private void initializeAnimator() {
final View rocket = rootView.findViewById(R.id.rocket_page4);
Animator rocketScaleAnimator = getScaleAndVisibilityAnimator(rocket);
Animator rocketRotationAnimator = getRotationAnimator(rocket);
Animator rocketTranslationAnimator = getTranslationAnimator(rocket);
animator = new AnimatorSet();
animator.setStartDelay(600);
animator.playTogether(rocketScaleAnimator, rocketRotationAnimator, rocketTranslationAnimator);
}
/**
* Performs checks to scroll animate the itemView and in case, it animates the view.
* <p><b>Note:</b> If you have to change at runtime the LayoutManager <i>and</i> add
* Scrollable Headers too, consider to add them in post, using a {@code delay >= 0},
* otherwise scroll animations on all items will not start correctly.</p>
*
* @param holder the ViewHolder just bound
* @param position the current item position
* @since 5.0.0-b1
*/
protected final void animateView(final RecyclerView.ViewHolder holder, final int position) {
if (mRecyclerView == null) {
return;
}
// Use always the max child count reached
if (mMaxChildViews < mRecyclerView.getChildCount()) {
mMaxChildViews = mRecyclerView.getChildCount();
}
// Animate only during initial loading?
if (onlyEntryAnimation && mLastAnimatedPosition >= mMaxChildViews) {
isForwardEnabled = false;
}
int lastVisiblePosition = getFlexibleLayoutManager().findLastVisibleItemPosition();
// log.v("animateView isForwardEnabled=%s isReverseEnabled=%s isFastScroll=%s isNotified=%s mLastAnimatedPosition=%s mMaxChildViews=%s %s",
// isForwardEnabled, isReverseEnabled, isFastScroll, mAnimatorNotifierObserver.isPositionNotified(), mLastAnimatedPosition,
// mMaxChildViews, (!isReverseEnabled ? " Pos>LasVisPos=" + (position > lastVisiblePosition) : "")
// );
if ((isForwardEnabled || isReverseEnabled)
&& !isFastScroll && holder instanceof FlexibleViewHolder
&& (!mAnimatorNotifierObserver.isPositionNotified() || isScrollableHeaderOrFooter(position))
&& (isScrollableHeaderOrFooter(position)
|| (isForwardEnabled && position > lastVisiblePosition)
|| (isReverseEnabled && position < lastVisiblePosition)
|| (position == 0 && mMaxChildViews == 0))) {
// Cancel animation is necessary when fling
int hashCode = holder.itemView.hashCode();
cancelExistingAnimation(hashCode);
// User animators
List<Animator> animators = new ArrayList<>();
FlexibleViewHolder flexibleViewHolder = (FlexibleViewHolder) holder;
flexibleViewHolder.scrollAnimators(animators, position, position >= lastVisiblePosition);
// Execute the animations together
AnimatorSet set = new AnimatorSet();
set.playTogether(animators);
set.setInterpolator(mInterpolator);
// Single view duration
long duration = mDuration;
for (Animator animator : animators) {
if (animator.getDuration() != DEFAULT_DURATION) {
duration = animator.getDuration();
}
}
set.setDuration(duration);
set.addListener(new HelperAnimatorListener(hashCode));
if (mEntryStep) {
// Stop stepDelay when screen is filled
set.setStartDelay(calculateAnimationDelay(holder, position));
}
set.start();
mAnimators.put(hashCode, set);
//log.v("animateView Scroll animation on position %s", position);
}
mAnimatorNotifierObserver.clearNotified();
// Update last animated position
mLastAnimatedPosition = position;
}
private void showLayout(AttachAlertLayout layout) {
if (viewChangeAnimator != null || commentsAnimator != null) {
return;
}
if (currentAttachLayout == layout) {
currentAttachLayout.scrollToTop();
return;
}
if (layout == photoLayout) {
selectedId = 1;
} else if (layout == audioLayout) {
selectedId = 3;
} else if (layout == documentLayout) {
selectedId = 4;
} else if (layout == contactsLayout) {
selectedId = 5;
} else if (layout == locationLayout) {
selectedId = 6;
} else if (layout == pollLayout) {
selectedId = 9;
}
int count = buttonsRecyclerView.getChildCount();
for (int a = 0; a < count; a++) {
View child = buttonsRecyclerView.getChildAt(a);
if (child instanceof AttachButton) {
AttachButton attachButton = (AttachButton) child;
attachButton.updateCheckedState(true);
}
}
int t = currentAttachLayout.getFirstOffset() - AndroidUtilities.dp(11) - scrollOffsetY[0];
nextAttachLayout = layout;
if (Build.VERSION.SDK_INT >= 20) {
container.setLayerType(View.LAYER_TYPE_HARDWARE, null);
}
actionBar.setVisibility(nextAttachLayout.needsActionBar() != 0 ? View.VISIBLE : View.INVISIBLE);
actionBarShadow.setVisibility(actionBar.getVisibility());
if (actionBar.isSearchFieldVisible()) {
actionBar.closeSearchField();
}
currentAttachLayout.onHide();
nextAttachLayout.onShow();
nextAttachLayout.setVisibility(View.VISIBLE);
nextAttachLayout.setAlpha(0.0f);
if (layout.getParent() != null) {
containerView.removeView(nextAttachLayout);
}
int index = containerView.indexOfChild(currentAttachLayout);
containerView.addView(nextAttachLayout, nextAttachLayout == locationLayout ? index : index + 1, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
nextAttachLayout.setTranslationY(AndroidUtilities.dp(78));
AnimatorSet animator = new AnimatorSet();
animator.playTogether(ObjectAnimator.ofFloat(currentAttachLayout, View.TRANSLATION_Y, AndroidUtilities.dp(78) + t),
ObjectAnimator.ofFloat(currentAttachLayout, ATTACH_ALERT_LAYOUT_TRANSLATION, 0.0f, 1.0f));
animator.setInterpolator(CubicBezierInterpolator.DEFAULT);
animator.setDuration(180);
animator.setStartDelay(20);
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
currentAttachLayout.setAlpha(0.0f);
SpringAnimation springAnimation = new SpringAnimation(nextAttachLayout, DynamicAnimation.TRANSLATION_Y, 0);
springAnimation.getSpring().setDampingRatio(0.7f);
springAnimation.getSpring().setStiffness(400.0f);
springAnimation.addUpdateListener((animation12, value, velocity) -> {
if (nextAttachLayout == pollLayout) {
updateSelectedPosition(1);
}
nextAttachLayout.onContainerTranslationUpdated();
containerView.invalidate();
});
springAnimation.addEndListener((animation1, canceled, value, velocity) -> {
if (Build.VERSION.SDK_INT >= 20) {
container.setLayerType(View.LAYER_TYPE_NONE, null);
}
viewChangeAnimator = null;
containerView.removeView(currentAttachLayout);
currentAttachLayout.setVisibility(View.GONE);
currentAttachLayout.onHidden();
nextAttachLayout.onShown();
currentAttachLayout = nextAttachLayout;
nextAttachLayout = null;
scrollOffsetY[0] = scrollOffsetY[1];
});
viewChangeAnimator = springAnimation;
springAnimation.start();
}
});
viewChangeAnimator = animator;
animator.start();
}