// Define Animations public void initializeAnimatorSets() { rotate = new AnimatorSet(); unrotate = new AnimatorSet(); Animator[] rotationAnimations = new Animator[getChildCount() * 2]; // set rotate float spaceForEach = (float) (Math.cos((double) MapView.rotationAngle) * MapView.rotationYScale * getHeight()); for (int i = 0; i < getChildCount(); i++) { ((MapView) getChildAt(i)).initPivots(); rotationAnimations[2 * i] = new ObjectAnimator() .ofFloat( getChildAt(getChildCount() - i - 1), "translationY", (float) ((i - activeLayer) * spaceForEach - (getHeight() - spaceForEach) / 2)); // the "getChildCount() - i - 1" bit reverses the ordering of // the layers. Good candidate for refactoring rotationAnimations[2 * i + 1] = ((MapView) getChildAt(getChildCount() - i - 1)).rotate; } for (int i = 0; i < rotationAnimations.length - 1; i++) { rotate.play(rotationAnimations[i]).with(rotationAnimations[i + 1]); } // set unrotate unrotate.play(ObjectAnimator.ofInt(this, "scrollY", 0)); }
private void createDefaultIconAnimation() { ObjectAnimator collapseAnimator = ObjectAnimator.ofFloat( mImageToggle, "rotation", mLabelsPosition == LABELS_POSITION_LEFT ? OPENED_PLUS_ROTATION_LEFT : OPENED_PLUS_ROTATION_RIGHT, CLOSED_PLUS_ROTATION); ObjectAnimator expandAnimator = ObjectAnimator.ofFloat( mImageToggle, "rotation", CLOSED_PLUS_ROTATION, mLabelsPosition == LABELS_POSITION_LEFT ? OPENED_PLUS_ROTATION_LEFT : OPENED_PLUS_ROTATION_RIGHT); mOpenAnimatorSet.play(expandAnimator); mCloseAnimatorSet.play(collapseAnimator); mOpenAnimatorSet.setInterpolator(mOpenInterpolator); mCloseAnimatorSet.setInterpolator(mCloseInterpolator); mOpenAnimatorSet.setDuration(ANIMATION_DURATION); mCloseAnimatorSet.setDuration(ANIMATION_DURATION); }
private Animator createSegue(View from, View to, Flow.Direction direction) { boolean backward = direction == Flow.Direction.BACKWARD; int fromTranslation = backward ? from.getWidth() : -from.getWidth(); int toTranslation = backward ? -to.getWidth() : to.getWidth(); AnimatorSet set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(from, View.TRANSLATION_X, fromTranslation)); set.play(ObjectAnimator.ofFloat(to, View.TRANSLATION_X, toTranslation, 0)); return set; }
private void startAnimation(View img, final Intent intent) { // ObjectAnimator oaTranslationX = ObjectAnimator.ofFloat(img, // "translationX", 0, mScreenWidth / 2); // ObjectAnimator oaTranslationY = ObjectAnimator.ofFloat(img, // "translationY", 0, mScreenHeight / 2); ObjectAnimator oaScaleX = ObjectAnimator.ofFloat(img, "scaleX", 0.5f, 1.2f, 1f); ObjectAnimator oaScaleY = ObjectAnimator.ofFloat(img, "scaleY", 0.5f, 1.2f, 1f); // oaTranslationX.setDuration(1000); // oaTranslationY.setDuration(1000); // oaScaleX.setDuration(1000); // oaScaleY.setDuration(1000); AnimatorSet set = new AnimatorSet(); set.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { isLocked = true; super.onAnimationStart(animation); } @Override public void onAnimationEnd(Animator animation) { Log.e("", "动画完成"); isLocked = false; startActivity(intent); } }); set.play(oaScaleX).with(oaScaleY); set.setDuration(500); if (!isLocked) { set.start(); } }
private AnimatorSet startAniMoveRightToCenter(View rightDot) { int dotDiameter = (int) getResources().getDimension(R.dimen.loading_dot_size); int dotPadding = (int) getResources().getDimension(R.dimen.loading_dot_padding); AnimatorSet moveRightToCentral = new AnimatorSet(); ObjectAnimator rightDotToCentral = ObjectAnimator.ofFloat(rightDot, "translationX", 0, -dotPadding - dotDiameter); rightDotColorChange = ValueAnimator.ofObject( new ArgbEvaluator(), getResources().getColor(R.color.dot_normal), getResources().getColor(R.color.dot_active)); final GradientDrawable rightDotBg = (GradientDrawable) rightDot.getBackground(); rightDotColorChange.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(final ValueAnimator animator) { rightDotBg.setColor((Integer) animator.getAnimatedValue()); } }); rightDotColorChange.setDuration(aniDuration); rightDotColorChange.addListener(this); moveRightToCentral.play(rightDotColorChange).with(rightDotToCentral); return moveRightToCentral; }
/** 开启打开动画 */ private void startAnim() { ObjectAnimator tranAnimY = ObjectAnimator.ofFloat(mMenuViewSmall, "translationY", 0, -20); ObjectAnimator tranAnimPointX = ObjectAnimator.ofFloat(mMenuViewSmall, "translationX", 0, viewMoveX); ObjectAnimator tranAnimPointY = ObjectAnimator.ofFloat(mMenuViewSmall, "translationY", -20, viewMoveY); ObjectAnimator scaleAnimX = ObjectAnimator.ofFloat(mMenuViewSmall, "scaleX", 1.0f, (toValueX + 1.0f)); ObjectAnimator scaleAnimY = ObjectAnimator.ofFloat(mMenuViewSmall, "scaleY", 1.0f, (toValueY + 1.0f)); AnimatorSet set = new AnimatorSet(); set.setDuration(500); set.play(tranAnimY) .before(tranAnimPointX) .before(tranAnimPointY) .before(scaleAnimX) .before(scaleAnimY); scaleAnimX.addUpdateListener( new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float value = (float) animation.getAnimatedValue(); // mMenuViewSmall.setScaleX(value); mContentView.setAlpha((float) (1 - ((value - 1) / toValueX) * 0.5)); mContentView.setScaleX((float) (1 - ((value - 1) / toValueX) * 0.2)); mContentView.setScaleY((float) (1 - ((value - 1) / toValueX) * 0.2)); } }); set.addListener(this); set.start(); }
private void flip(final View v1, final View v2, final boolean scale, boolean reverse) { final int duration = 300; final int degree = reverse ? 90 : -90; final int degree2 = -degree; final ObjectAnimator a, b; if (!scale) { a = ObjectAnimator.ofFloat(v1, "rotationY", 0, degree); b = ObjectAnimator.ofFloat(v2, "rotationY", degree2, 0); } else { final float scaleX = 0.5f; final float scaleY = 0.5f; a = ObjectAnimator.ofPropertyValuesHolder( v1, PropertyValuesHolder.ofFloat("rotationY", 0, degree), PropertyValuesHolder.ofFloat("scaleX", 1, scaleX), PropertyValuesHolder.ofFloat("scaleY", 1, scaleY)); b = ObjectAnimator.ofPropertyValuesHolder( v2, PropertyValuesHolder.ofFloat("rotationY", degree2, 0), PropertyValuesHolder.ofFloat("scaleX", scaleX, 1), PropertyValuesHolder.ofFloat("scaleY", scaleY, 1)); } a.setInterpolator(new LinearInterpolator()); b.setInterpolator(new LinearInterpolator()); a.setDuration(duration); b.setDuration(duration); a.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) {} @Override public void onAnimationEnd(Animator animation) { v1.setVisibility(View.GONE); v2.setVisibility(View.VISIBLE); if (scale) { // 恢复scale v1.setScaleX(1); v1.setScaleY(1); } } @Override public void onAnimationCancel(Animator animation) {} @Override public void onAnimationRepeat(Animator animation) {} }); v1.setVisibility(View.VISIBLE); v2.setVisibility(View.GONE); AnimatorSet set = new AnimatorSet(); set.play(a).before(b); set.start(); }
private void updateHeartButton(final CellFeedViewHolder holder, boolean animated) { if (animated) { if (!likeAnimations.containsKey(holder)) { AnimatorSet animatorSet = new AnimatorSet(); likeAnimations.put(holder, animatorSet); ObjectAnimator rotationAnim = ObjectAnimator.ofFloat(holder.btnLike, "rotation", 0f, 360f); rotationAnim.setDuration(300); rotationAnim.setInterpolator(ACCELERATE_INTERPOLATOR); ObjectAnimator bounceAnimX = ObjectAnimator.ofFloat(holder.btnLike, "scaleX", 0.2f, 1f); bounceAnimX.setDuration(300); bounceAnimX.setInterpolator(OVERSHOOT_INTERPOLATOR); ObjectAnimator bounceAnimY = ObjectAnimator.ofFloat(holder.btnLike, "scaleY", 0.2f, 1f); bounceAnimY.setDuration(300); bounceAnimY.setInterpolator(OVERSHOOT_INTERPOLATOR); bounceAnimY.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { holder.btnLike.setImageResource(R.drawable.ic_heart_red); } }); animatorSet.play(rotationAnim); animatorSet.play(bounceAnimX).with(bounceAnimY).after(rotationAnim); animatorSet.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { resetLikeAnimationState(holder); } }); animatorSet.start(); } } else { if (likedPositions.contains(holder.getPosition())) { holder.btnLike.setImageResource(R.drawable.ic_heart_red); } else { holder.btnLike.setImageResource(R.drawable.ic_heart_outline_grey); } } }
@Override public void showFabs() { AnimatorSet animatorSet = new AnimatorSet(); animatorSet.play(hideTextContainer()); animatorSet.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { animatedTextContainer = true; } @Override public void onAnimationEnd(Animator animation) { textContainerisShown = false; ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) viewHolder.rvChat.getLayoutParams(); Log.d( "height = ", String.valueOf( ((ViewGroup.LayoutParams) viewHolder.textContainer.getLayoutParams()).height)); lp.setMargins(lp.leftMargin, lp.topMargin, lp.rightMargin, 0); viewHolder.rvChat.requestLayout(); viewHolder.rvChat.scrollToPosition(0); viewHolder.fabAdd.setImageResource(R.drawable.add); AnimatorSet newAnimatorSet = new AnimatorSet(); viewHolder.fabAdd.setAlpha(0.64f); newAnimatorSet.playTogether(createExpandAnimator(viewHolder.fabAdd, offset)); newAnimatorSet.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) {} @Override public void onAnimationEnd(Animator animation) { animatedTextContainer = false; } @Override public void onAnimationCancel(Animator animation) {} @Override public void onAnimationRepeat(Animator animation) {} }); newAnimatorSet.start(); } @Override public void onAnimationCancel(Animator animation) {} @Override public void onAnimationRepeat(Animator animation) {} }); animatorSet.start(); }
private void combine() { ObjectAnimator moveIn = ObjectAnimator.ofFloat(tv, "translationX", -500f, 0f); ObjectAnimator rotate = ObjectAnimator.ofFloat(tv, "rotation", 0f, 360f); ObjectAnimator fadeInOut = ObjectAnimator.ofFloat(tv, "alpha", 1f, 0f, 1f); AnimatorSet animSet = new AnimatorSet(); animSet.play(rotate).with(fadeInOut).after(moveIn); animSet.setDuration(5000); animSet.start(); }
@Override public void animate() { final ViewGroup parentView = (ViewGroup) view.getParent(); final FrameLayout slideOutFrame = new FrameLayout(view.getContext()); final int positionView = parentView.indexOfChild(view); slideOutFrame.setLayoutParams(view.getLayoutParams()); slideOutFrame.setClipChildren(true); parentView.removeView(view); slideOutFrame.addView(view); parentView.addView(slideOutFrame, positionView); switch (direction) { case DIRECTION_LEFT: slideAnim = ObjectAnimator.ofFloat( view, View.TRANSLATION_X, view.getTranslationX() - view.getWidth()); break; case DIRECTION_RIGHT: slideAnim = ObjectAnimator.ofFloat( view, View.TRANSLATION_X, view.getTranslationX() + view.getWidth()); break; case DIRECTION_UP: slideAnim = ObjectAnimator.ofFloat( view, View.TRANSLATION_Y, view.getTranslationY() - view.getHeight()); break; case DIRECTION_DOWN: slideAnim = ObjectAnimator.ofFloat( view, View.TRANSLATION_Y, view.getTranslationY() + view.getHeight()); break; default: break; } AnimatorSet slideSet = new AnimatorSet(); slideSet.play(slideAnim); slideSet.setInterpolator(interpolator); slideSet.setDuration(duration); slideSet.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { view.setVisibility(View.INVISIBLE); slideAnim.reverse(); slideOutFrame.removeAllViews(); parentView.removeView(slideOutFrame); parentView.addView(view, positionView); if (getListener() != null) { getListener().onAnimationEnd(SlideOutUnderneathAnimation.this); } } }); slideSet.start(); }
private Animator createTranslateAlphaAnimator( View v, float fromTranslateX, float toTranslateX, float fromAlpha, float toAlpha) { ObjectAnimator translateAnimator = ObjectAnimator.ofFloat(v, "translationX", fromTranslateX, toTranslateX); translateAnimator.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime)); Animator alphaAnimator = createAlphaAnimator(v, fromAlpha, toAlpha); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.play(translateAnimator).with(alphaAnimator); return animatorSet; }
public void dismissMTSInfo() { Log.e(TAG, "Dismiss MTS information."); hasShow = false; ObjectAnimator translationUp = ObjectAnimator.ofFloat( Mtslayout, "Y", getResources().getInteger(R.integer.mtslayout_value)); AnimatorSet as = new AnimatorSet(); as.play(translationUp); as.start(); }
/** 初始化属性 */ private void init() { // x y方向上的缩放 ObjectAnimator xScaleAnimator = ObjectAnimator.ofFloat(this, "scaleX", START_SCALE, END_SCALE); ObjectAnimator yScaleAnimator = ObjectAnimator.ofFloat(this, "scaleY", START_SCALE, END_SCALE); // 组合动画 animSet = new AnimatorSet(); animSet.play(xScaleAnimator).with(yScaleAnimator); animSet.setDuration(SCALE_DURATION); }
public void animateToVisibility(int visibility) { if (mVisibilityAnim != null) { mVisibilityAnim.cancel(); } if (visibility == VISIBLE) { if (getVisibility() != VISIBLE) { setAlpha(0); if (mSplitView != null && mMenuView != null) { mMenuView.setAlpha(0); } } ObjectAnimator anim = ObjectAnimator.ofFloat(this, "alpha", 1); anim.setDuration(FADE_DURATION); anim.setInterpolator(sAlphaInterpolator); if (mSplitView != null && mMenuView != null) { AnimatorSet set = new AnimatorSet(); ObjectAnimator splitAnim = ObjectAnimator.ofFloat(mMenuView, "alpha", 1); splitAnim.setDuration(FADE_DURATION); set.addListener(mVisAnimListener.withFinalVisibility(visibility)); set.play(anim).with(splitAnim); set.start(); } else { anim.addListener(mVisAnimListener.withFinalVisibility(visibility)); anim.start(); } } else { ObjectAnimator anim = ObjectAnimator.ofFloat(this, "alpha", 0); anim.setDuration(FADE_DURATION); anim.setInterpolator(sAlphaInterpolator); if (mSplitView != null && mMenuView != null) { AnimatorSet set = new AnimatorSet(); ObjectAnimator splitAnim = ObjectAnimator.ofFloat(mMenuView, "alpha", 0); splitAnim.setDuration(FADE_DURATION); set.addListener(mVisAnimListener.withFinalVisibility(visibility)); set.play(anim).with(splitAnim); set.start(); } else { anim.addListener(mVisAnimListener.withFinalVisibility(visibility)); anim.start(); } } }
public void dismissInfoView() { hasShow = false; ObjectAnimator translationUp = ObjectAnimator.ofFloat( mOSDLayout, "Y", mContext.getResources().getInteger(R.integer.ChannelInfo_details_animator_height)); AnimatorSet as = new AnimatorSet(); as.play(translationUp); as.start(); }
private void startRipple(final Runnable animationEndRunnable) { if (eventCancelled) return; float endRadius = getEndRadius(); cancelAnimations(); rippleAnimator = new AnimatorSet(); rippleAnimator.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (!ripplePersistent) { setRadius(0); setRippleAlpha(rippleAlpha); } if (animationEndRunnable != null && rippleDelayClick) { animationEndRunnable.run(); } childView.setPressed(false); } }); ObjectAnimator ripple = ObjectAnimator.ofFloat(this, radiusProperty, radius, endRadius); ripple.setDuration(rippleDuration); ripple.setInterpolator(new DecelerateInterpolator()); ObjectAnimator fade = ObjectAnimator.ofInt(this, circleAlphaProperty, rippleAlpha, 0); fade.setDuration(rippleFadeDuration); fade.setInterpolator(new AccelerateInterpolator()); fade.setStartDelay(rippleDuration - rippleFadeDuration - FADE_EXTRA_DELAY); if (ripplePersistent) { rippleAnimator.play(ripple); } else if (getRadius() > endRadius) { fade.setStartDelay(0); rippleAnimator.play(fade); } else { rippleAnimator.playTogether(ripple, fade); } rippleAnimator.start(); }
public void checked(FloatingActionButton fabView, boolean isChecked) { final float conversion = getResources().getDisplayMetrics().density; if (isChecked) { AnimatorSet animView = new AnimatorSet(); ValueAnimator tran = ObjectAnimator.ofFloat( mAnimate, "y", mAnimate.getY(), mAnimate.getY() - 345 * conversion); tran.setDuration(300); tran.setInterpolator(new AccelerateDecelerateInterpolator()); ValueAnimator fabRot = ObjectAnimator.ofFloat(fabView, "rotation", 0f, 135f); fabRot.setDuration(400); ValueAnimator fabAlpha = ObjectAnimator.ofFloat(fabView, "alpha", 1f, 0f); fabAlpha.setDuration(100); ValueAnimator fabTran = ObjectAnimator.ofFloat(fabView, "y", fabView.getY(), fabView.getY() - 16 * conversion); fabTran.setDuration(200); animView.play(fabRot).before(fabAlpha); animView.play(fabAlpha).with(fabTran); animView.play(fabAlpha).with(tran); mAnimate.setDisplayedChild(1); animView.start(); } else { AnimatorSet animOut = new AnimatorSet(); ValueAnimator fabRot2 = ObjectAnimator.ofFloat(fabView, "rotation", 135f, 0f); fabRot2.setDuration(200); ValueAnimator fabAlpha2 = ObjectAnimator.ofFloat(fabView, "alpha", 0f, 1f); fabAlpha2.setDuration(300); ValueAnimator fabTran2 = ObjectAnimator.ofFloat(fabView, "y", fabView.getY(), fabView.getY() + 16 * conversion); fabTran2.setDuration(200); ValueAnimator tran2 = ObjectAnimator.ofFloat( mAnimate, "y", mAnimate.getY(), mAnimate.getY() + 345 * conversion); tran2.setDuration(300); animOut.play(tran2).before(fabAlpha2); animOut.play(fabAlpha2).with(fabTran2); animOut.play(fabAlpha2).with(fabRot2); animOut.start(); mAnimate.setDisplayedChild(0); } }
private void animatePhotoLike(final CellFeedViewHolder holder) { if (!likeAnimations.containsKey(holder)) { holder.vBgLike.setVisibility(View.VISIBLE); holder.ivLike.setVisibility(View.VISIBLE); holder.vBgLike.setScaleY(0.1f); holder.vBgLike.setScaleX(0.1f); holder.vBgLike.setAlpha(1f); holder.ivLike.setScaleY(0.1f); holder.ivLike.setScaleX(0.1f); AnimatorSet animatorSet = new AnimatorSet(); likeAnimations.put(holder, animatorSet); ObjectAnimator bgScaleYAnim = ObjectAnimator.ofFloat(holder.vBgLike, "scaleY", 0.1f, 1f); bgScaleYAnim.setDuration(200); bgScaleYAnim.setInterpolator(DECCELERATE_INTERPOLATOR); ObjectAnimator bgScaleXAnim = ObjectAnimator.ofFloat(holder.vBgLike, "scaleX", 0.1f, 1f); bgScaleXAnim.setDuration(200); bgScaleXAnim.setInterpolator(DECCELERATE_INTERPOLATOR); ObjectAnimator bgAlphaAnim = ObjectAnimator.ofFloat(holder.vBgLike, "alpha", 1f, 0f); bgAlphaAnim.setDuration(200); bgAlphaAnim.setStartDelay(150); bgAlphaAnim.setInterpolator(DECCELERATE_INTERPOLATOR); ObjectAnimator imgScaleUpYAnim = ObjectAnimator.ofFloat(holder.ivLike, "scaleY", 0.1f, 1f); imgScaleUpYAnim.setDuration(300); imgScaleUpYAnim.setInterpolator(DECCELERATE_INTERPOLATOR); ObjectAnimator imgScaleUpXAnim = ObjectAnimator.ofFloat(holder.ivLike, "scaleX", 0.1f, 1f); imgScaleUpXAnim.setDuration(300); imgScaleUpXAnim.setInterpolator(DECCELERATE_INTERPOLATOR); ObjectAnimator imgScaleDownYAnim = ObjectAnimator.ofFloat(holder.ivLike, "scaleY", 1f, 0f); imgScaleDownYAnim.setDuration(300); imgScaleDownYAnim.setInterpolator(ACCELERATE_INTERPOLATOR); ObjectAnimator imgScaleDownXAnim = ObjectAnimator.ofFloat(holder.ivLike, "scaleX", 1f, 0f); imgScaleDownXAnim.setDuration(300); imgScaleDownXAnim.setInterpolator(ACCELERATE_INTERPOLATOR); animatorSet.playTogether( bgScaleYAnim, bgScaleXAnim, bgAlphaAnim, imgScaleUpYAnim, imgScaleUpXAnim); animatorSet.play(imgScaleDownYAnim).with(imgScaleDownXAnim).after(imgScaleUpYAnim); animatorSet.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { resetLikeAnimationState(holder); } }); animatorSet.start(); } }
public void showNext() { if (height <= 0) { height = topToast1.getHeight(); } ObjectAnimator anim1 = ObjectAnimator.ofFloat(topToastArray[(showPosition + 1) % length], "y", -height, 0f); ObjectAnimator anim2 = ObjectAnimator.ofFloat(topToastArray[showPosition], "y", 0f, height); AnimatorSet animSet = new AnimatorSet(); animSet.play(anim1).with(anim2); animSet.setDuration(500); animSet.start(); showPosition = (showPosition + 1) % length; }
// multiple object animator objects to be run in parallel public void runObjectAnimators(View view) { ObjectAnimator oaX = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, TX_END); ObjectAnimator oaY = ObjectAnimator.ofFloat(view, View.TRANSLATION_Y, TY_END); // oaX.start(); // just put the start on the end of the above definitions and delete the object // assignment // oaY.start(); // object assignment used with below example of animation set for parallel // or to run them in parallel AnimatorSet animatorSet = new AnimatorSet(); animatorSet.play(oaX).with(oaY); animatorSet.setDuration(1000); // animatorSet.setInterpolator(new OvershootInterpolator()); // working animatorSet.start(); }
@Override public AnimatorSet createAnimatorSet() { ViewHelper.setClipChildren(targetView, false); AnimatorSet rotationSet = new AnimatorSet(); rotationSet.play( ObjectAnimator.ofFloat(targetView, View.ROTATION, targetView.getRotation() + degrees)); rotationSet.setInterpolator(interpolator); rotationSet.setDuration(duration); if (listener != null) { rotationSet.addListener(listener); } return rotationSet; }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void animateTextColor(int targetColor) { if (mCurrentColorAnim != null) { mCurrentColorAnim.cancel(); } mCurrentColorAnim = new AnimatorSet(); mCurrentColorAnim.setDuration(DragView.COLOR_CHANGE_DURATION); if (mSrcFilter == null) { mSrcFilter = new ColorMatrix(); mDstFilter = new ColorMatrix(); mCurrentFilter = new ColorMatrix(); } DragView.setColorScale(getTextColor(), mSrcFilter); DragView.setColorScale(targetColor, mDstFilter); ValueAnimator anim1 = ValueAnimator.ofObject( new FloatArrayEvaluator(mCurrentFilter.getArray()), mSrcFilter.getArray(), mDstFilter.getArray()); anim1.addUpdateListener( new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { mDrawable.setColorFilter(new ColorMatrixColorFilter(mCurrentFilter)); invalidate(); } }); mCurrentColorAnim.play(anim1); mCurrentColorAnim.play(ObjectAnimator.ofArgb(this, "textColor", targetColor)); mCurrentColorAnim.start(); }
private void animateButton(View loginButton) { loginButton.setScaleX(0f); loginButton.setScaleY(0f); loginButton.setAlpha(0f); ObjectAnimator animator1 = ObjectAnimator.ofFloat(loginButton, "alpha", 1f); animator1.setDuration(1000); ObjectAnimator animator2 = ObjectAnimator.ofFloat(loginButton, "scaleX", 1f); animator2.setDuration(1000); ObjectAnimator animator3 = ObjectAnimator.ofFloat(loginButton, "scaleY", 1f); animator3.setDuration(1000); AnimatorSet set = new AnimatorSet(); set.play(animator1).with(animator2).with(animator3); set.start(); }
private void scaleToLarge(View item) { if (!item.isFocused()) { return; } animatorSet = new AnimatorSet(); largeX = ObjectAnimator.ofFloat(item, "ScaleX", 1f, scale); ObjectAnimator largeY = ObjectAnimator.ofFloat(item, "ScaleY", 1f, scale); ObjectAnimator cursorX = ObjectAnimator.ofFloat(cursor, "ScaleX", 1f, scale); ObjectAnimator cursorY = ObjectAnimator.ofFloat(cursor, "ScaleY", 1f, scale); animatorSet.setDuration(durationLarge); animatorSet.play(largeX).with(largeY).with(cursorX).with(cursorY); animatorSet.start(); }
/** * Constructs an animator for the specified property on a group of views. See {@link * ObjectAnimator#ofFloat(Object, String, float...)} for implementation details. * * @param property The property being animated. * @param value The value to which that property should animate. * @param views The target views to animate. * @return An animator for all the specified views. */ private static Animator groupAnimatorOfFloat( Property<View, Float> property, float value, View... views) { AnimatorSet animSet = new AnimatorSet(); AnimatorSet.Builder builder = null; for (int i = views.length - 1; i >= 0; i--) { final Animator anim = ObjectAnimator.ofFloat(views[i], property, value); if (builder == null) { builder = animSet.play(anim); } else { builder.with(anim); } } return animSet; }
/** 对TextView进行伸缩处理 */ private void flexibleHeight() { isExpand = !isExpand; int textHeight = 0; float startDegree = 0.0f; float endDegree = 180.0f; if (isExpand) { // 如果是展开模式,那么取消最大行为maxLine的限制 textHeight = contentLine * mTextView.getLineHeight(); mTextView.setMaxLines(contentLine); } else { textHeight = mTextView.getLineHeight() * maxLine; endDegree = 0.0f; startDegree = 180.0f; } final LayoutParams mParam = (LayoutParams) mTextView.getLayoutParams(); // TextView的平移动画 ValueAnimator animator_textView = ValueAnimator.ofInt(mTextView.getHeight(), textHeight); animator_textView.addUpdateListener( new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { mParam.height = (Integer) animation.getAnimatedValue(); mTextView.setLayoutParams(mParam); } }); // imageView的旋转动画 ObjectAnimator animator_img = ObjectAnimator.ofFloat(mImageView, "rotation", startDegree, endDegree); AnimatorSet mAnimatorSets = new AnimatorSet(); mAnimatorSets.setDuration(500); mAnimatorSets.play(animator_img).with(animator_textView); mAnimatorSets.start(); mAnimatorSets.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); // 动画结束之后,如果是非展开模式,则设置最大行数为maxLine if (!isExpand) { mTextView.setMaxLines(maxLine); } } }); }
private void animateLogo(View vkLogo) { vkLogo.setScaleX(0f); vkLogo.setScaleY(0f); vkLogo.setAlpha(0f); ObjectAnimator animator1 = ObjectAnimator.ofFloat(vkLogo, "rotation", 720f); animator1.setDuration(1000); ObjectAnimator animator2 = ObjectAnimator.ofFloat(vkLogo, "alpha", 1f); animator2.setDuration(1000); ObjectAnimator animator3 = ObjectAnimator.ofFloat(vkLogo, "scaleX", 1f); animator3.setDuration(1000); ObjectAnimator animator4 = ObjectAnimator.ofFloat(vkLogo, "scaleY", 1f); animator4.setDuration(1000); AnimatorSet set = new AnimatorSet(); set.play(animator1).with(animator2).with(animator3).with(animator4); set.start(); }
private void doFadeAnimation() { ObjectAnimator fadeCamcord = ObjectAnimator.ofFloat(mCamcordImage, "alpha", 0f, 1f); fadeCamcord.setDuration(700); ObjectAnimator fadeClock = ObjectAnimator.ofFloat(mClockImage, "alpha", 0f, 1f); fadeClock.setDuration(700); ObjectAnimator fadeGraph = ObjectAnimator.ofFloat(mGraphImage, "alpha", 0f, 1f); fadeGraph.setDuration(700); ObjectAnimator fadeAudio = ObjectAnimator.ofFloat(mAudioImage, "alpha", 0f, 1f); fadeAudio.setDuration(700); ObjectAnimator fadeQuote = ObjectAnimator.ofFloat(mQuoteImage, "alpha", 0f, 1f); fadeQuote.setDuration(700); ObjectAnimator fadeMap = ObjectAnimator.ofFloat(mMapImage, "alpha", 0f, 1f); fadeMap.setDuration(700); ObjectAnimator fadeWordpress = ObjectAnimator.ofFloat(mWordPressImage, "alpha", 0f, 1f); fadeWordpress.setDuration(700); // 1 5 3 2 7 6 4 mAnimatorSet = new AnimatorSet(); fadeAudio.setStartDelay(50); fadeGraph.setStartDelay(200); fadeWordpress.setStartDelay(500); fadeClock.setStartDelay(700); fadeMap.setStartDelay(900); fadeQuote.setStartDelay(1100); mAnimatorSet .play(fadeCamcord) .with(fadeAudio) .with(fadeGraph) .with(fadeWordpress) .with(fadeClock) .with(fadeMap) .with(fadeQuote); mAnimatorSet.start(); }
private void startAnim(ImageView v) { ObjectAnimator scaleX = ObjectAnimator.ofFloat(v, "scaleX", 1f, 1.15f); ObjectAnimator scaleY = ObjectAnimator.ofFloat(v, "scaleY", 1f, 1.15f); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.setDuration(3000); animatorSet.setInterpolator(new DecelerateInterpolator()); animatorSet.play(scaleX).with(scaleY); animatorSet.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { Intent homeIntent = new Intent(MainActivity.this, HomePageActivity.class); startActivity(homeIntent); overridePendingTransition(R.anim.fade_in, R.anim.fade_out); finish(); } }); animatorSet.start(); }