下面列出了怎么用android.support.v4.view.animation.FastOutSlowInInterpolator的API类实例代码及写法,或者点击链接到github查看源代码。
@NonNull
@Override
protected Animator onPushAnimator(AnimationInfo from, final AnimationInfo to) {
final View fromView = from.mSceneView;
final View toView = to.mSceneView;
ValueAnimator fromAlphaAnimator = ObjectAnimator.ofFloat(fromView, View.ALPHA, 1.0f, 1.0f);//之前是0.7,但是动画后面会露出NavigationScene的背景色白色很怪异
fromAlphaAnimator.setInterpolator(new FastOutSlowInInterpolator());
fromAlphaAnimator.setDuration(120 * 20);
ValueAnimator toAlphaAnimator = ObjectAnimator.ofFloat(toView, View.ALPHA, 0.0f, 1.0f);
toAlphaAnimator.setInterpolator(new DecelerateInterpolator(2));
toAlphaAnimator.setDuration(120 * 20);
ValueAnimator toTranslateAnimator = ObjectAnimator.ofFloat(toView, View.TRANSLATION_Y, 0.08f * toView.getHeight(), 0);
toTranslateAnimator.setInterpolator(new DecelerateInterpolator(2.5f));
toTranslateAnimator.setDuration(200 * 20);
return TransitionUtils.mergeAnimators(fromAlphaAnimator, toAlphaAnimator, toTranslateAnimator);
}
@NonNull
@Override
protected Animator onPushAnimator(AnimationInfo from, final AnimationInfo to) {
final View fromView = from.mSceneView;
final View toView = to.mSceneView;
ValueAnimator fromAlphaAnimator = ObjectAnimator.ofFloat(fromView, View.ALPHA, 1.0f, 1.0f);//之前是0.7,但是动画后面会露出NavigationScene的背景色白色很怪异
fromAlphaAnimator.setInterpolator(new FastOutSlowInInterpolator());
fromAlphaAnimator.setDuration(120 * 20);
ValueAnimator toAlphaAnimator = ObjectAnimator.ofFloat(toView, View.ALPHA, 0.0f, 1.0f);
toAlphaAnimator.setInterpolator(new DecelerateInterpolator(2));
toAlphaAnimator.setDuration(120 * 20);
ValueAnimator toTranslateAnimator = ObjectAnimator.ofFloat(toView, View.TRANSLATION_Y, 0.08f * toView.getHeight(), 0);
toTranslateAnimator.setInterpolator(new DecelerateInterpolator(2.5f));
toTranslateAnimator.setDuration(200 * 20);
return TransitionUtils.mergeAnimators(fromAlphaAnimator, toAlphaAnimator, toTranslateAnimator);
}
@NonNull
@Override
protected Animator onPushAnimator(AnimationInfo from, final AnimationInfo to) {
if (to.mIsTranslucent) {
return mDialogSceneAnimatorExecutor.onPushAnimator(from, to);
}
final View fromView = from.mSceneView;
final View toView = to.mSceneView;
ValueAnimator fromAlphaAnimator = ObjectAnimator.ofFloat(fromView, View.ALPHA, 1.0f, 1.0f);//之前是0.7,但是动画后面会露出NavigationScene的背景色白色很怪异
fromAlphaAnimator.setInterpolator(new FastOutSlowInInterpolator());
fromAlphaAnimator.setDuration(120);
ValueAnimator toAlphaAnimator = ObjectAnimator.ofFloat(toView, View.ALPHA, 0.0f, 1.0f);
toAlphaAnimator.setInterpolator(new DecelerateInterpolator(2));
toAlphaAnimator.setDuration(120);
ValueAnimator toTranslateAnimator = ObjectAnimator.ofFloat(toView, View.TRANSLATION_Y, 0.08f * toView.getHeight(), 0);
toTranslateAnimator.setInterpolator(new DecelerateInterpolator(2.5f));
toTranslateAnimator.setDuration(200);
return TransitionUtils.mergeAnimators(fromAlphaAnimator, toAlphaAnimator, toTranslateAnimator);
}
private void createAnimators() {
alphaDownAnimator = ObjectAnimator.ofFloat(mView.get(), "alpha", config.getAlpha());
alphaUpAnimator = ObjectAnimator.ofFloat(mView.get(), "alpha", 1.0f);
scaleXDownAnimator = ObjectAnimator.ofFloat(mView.get(), "scaleX", config.getScaleDown());
scaleXUpAnimator = ObjectAnimator.ofFloat(mView.get(), "scaleX", 1.0f);
scaleYDownAnimator = ObjectAnimator.ofFloat(mView.get(), "scaleY", config.getScaleDown());
scaleYUpAnimator = ObjectAnimator.ofFloat(mView.get(), "scaleY", 1.0f);
downSet = new AnimatorSet();
downSet.setDuration(config.getDuration());
downSet.setInterpolator(new AccelerateInterpolator());
downSet.playTogether(alphaDownAnimator, scaleXDownAnimator, scaleYDownAnimator);
upSet = new AnimatorSet();
upSet.setDuration(config.getDuration());
upSet.setInterpolator(new FastOutSlowInInterpolator());
upSet.playTogether(alphaUpAnimator, scaleXUpAnimator, scaleYUpAnimator);
finalAnimationListener = new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
onClick(mView.get());
}
};
}
@Override
public void animateDismiss() {
//执行消失动画的时候,宽高可能改变了,所以需要修正动画的起始值
switch (popupAnimation) {
case TranslateFromLeft:
startTranslationX -= targetView.getMeasuredWidth() - oldWidth;
break;
case TranslateFromTop:
startTranslationY -= targetView.getMeasuredHeight() - oldHeight;
break;
case TranslateFromRight:
startTranslationX += targetView.getMeasuredWidth() - oldWidth;
break;
case TranslateFromBottom:
startTranslationY += targetView.getMeasuredHeight() - oldHeight;
break;
}
targetView.animate()
.translationX(startTranslationX)
.translationY(startTranslationY)
.setInterpolator(new FastOutSlowInInterpolator())
.setDuration(animationDuration)
.start();
}
@Override
public void animateShow() {
ValueAnimator animator = ValueAnimator.ofFloat(0, 1);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float fraction = animation.getAnimatedFraction();
targetView.setAlpha(floatEvaluator.evaluate(fraction, startAlpha, 1f));
targetView.scrollTo(intEvaluator.evaluate(fraction, startScrollX, 0),
intEvaluator.evaluate(fraction, startScrollY, 0));
float scale = floatEvaluator.evaluate(fraction, startScale, 1f);
targetView.setScaleX(scale);
if(!isOnlyScaleX)targetView.setScaleY(scale);
if(fraction>=.9f && targetView.getBackground()!=null) {
float alphaFraction = (fraction - .9f) / .1f;
targetView.getBackground().setAlpha((int) (alphaFraction*255));
}
}
});
animator.setDuration(animationDuration)
.setInterpolator(new FastOutSlowInInterpolator());
animator.start();
}
@Override
public void animateDismiss() {
ValueAnimator animator = ValueAnimator.ofFloat(0, 1);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float fraction = animation.getAnimatedFraction();
targetView.setAlpha(floatEvaluator.evaluate(fraction, 1f, startAlpha));
targetView.scrollTo(intEvaluator.evaluate(fraction, 0, startScrollX),
intEvaluator.evaluate(fraction, 0, startScrollY));
float scale = floatEvaluator.evaluate(fraction, 1f, startScale);
targetView.setScaleX(scale);
if(!isOnlyScaleX)targetView.setScaleY(scale);
if(targetView.getBackground()!=null)targetView.getBackground().setAlpha((int) (fraction*255));
}
});
animator.setDuration(animationDuration)
.setInterpolator(new FastOutSlowInInterpolator());
animator.start();
}
private void animateStageOut() {
final ValueAnimator animator = new ValueAnimator();
animator.setFloatValues(1F, 0F);
animator.setInterpolator(new FastOutSlowInInterpolator());
animator.setDuration(ANIMATION_DURATION);
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
targetParent.removeView(stage);
}
});
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
float currentAlpha = (float) valueAnimator.getAnimatedValue();
stage.setAlpha(currentAlpha);
}
});
animator.start();
}
private AnimatorSet buildIndicatorAnimatorTowards(TextView tab) {
ObjectAnimator xAnimator = ObjectAnimator.ofFloat(indicator, "X", indicator.getX(), tab.getX());
final ViewGroup.LayoutParams params = indicator.getLayoutParams();
ValueAnimator widthAnimator = ValueAnimator.ofInt(params.width, tab.getMeasuredWidth());
widthAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
params.width = (int) animation.getAnimatedValue();
indicator.setLayoutParams(params);
}
});
AnimatorSet set = new AnimatorSet();
set.setInterpolator(new FastOutSlowInInterpolator());
set.playTogether(xAnimator, widthAnimator);
return set;
}
public void resetStory() {
getSupportActionBar().setTitle(story.getTitle());
overlay.setClickable(false);
overlay.animate()
.alpha(0.0F)
.setDuration(200L)
.setInterpolator(new FastOutSlowInInterpolator())
.start();
switch (StoryDataProcess.Category.getEnum(story.getCategory())) {
case FILE:
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, FileStoryFragment.getInstance(story, false))
.commit();
break;
case TOPIC:
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, TopicStoryFragment.getInstance(story, false))
.commit();
break;
case LINK:
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, LinkStoryFragment.getInstance(story, false))
.commit();
break;
}
}
private void initInterpolations() {
ArrayList<Class> interpolatorList = new ArrayList<Class>() {{
add(FastOutSlowInInterpolator.class);
add(BounceInterpolator.class);
add(LinearInterpolator.class);
add(DecelerateInterpolator.class);
add(CycleInterpolator.class);
add(AnticipateInterpolator.class);
add(AccelerateDecelerateInterpolator.class);
add(AccelerateInterpolator.class);
add(AnticipateOvershootInterpolator.class);
add(FastOutLinearInInterpolator.class);
add(LinearOutSlowInInterpolator.class);
add(OvershootInterpolator.class);
}};
try {
interpolatorSelector = (Interpolator) interpolatorList.get(animateSelector).newInstance();
} catch (Exception e) {
e.printStackTrace();
}
}
private void handleVote(Upvote vote) {
shot.setVoted(fab.isChecked());
int count = vote.count;
if (!fab.isChecked() && count > 0) {
count -= 1;
}
if (count != shot.getVotes()) {
shot.setVotes(count);
updateVoteCount();
AnimatorSet s = new AnimatorSet();
s.setDuration(300).setInterpolator(new FastOutSlowInInterpolator());
s.playTogether(
ObjectAnimator.ofFloat(voteCount, "alpha", 0, 1, 1, 1),
ObjectAnimator.ofFloat(voteCount, "scaleX", 0.3f, 1.05f, 0.9f, 1),
ObjectAnimator.ofFloat(voteCount, "scaleY", 0.3f, 1.05f, 0.9f, 1));
s.start();
}
}
/**
*
* @param parent
* @param bb
* @param snackbar
*/
private void updateFabTranslationForSnackbar(CoordinatorLayout parent, BottomButton bb, View snackbar) {
float translationY = this.getFabTranslationYForSnackbar(parent, bb);
if (translationY != this.mTranslationY) {
ViewCompat.animate(bb).cancel();
if (Math.abs(translationY - this.mTranslationY) == (float) snackbar.getHeight()) {
ViewCompat.animate(bb).translationY(translationY).setInterpolator(new FastOutSlowInInterpolator())
.setListener((ViewPropertyAnimatorListener) null);
} else {
ViewCompat.setTranslationY(bb, translationY);
}
this.mTranslationY = translationY;
}
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Animator makeSearchPanelAnimator(boolean reverse) {
int width = container.getWidth();
int centerX = container.getRight()
+ container.getPaddingRight()
- resources.getDimensionPixelOffset(R.dimen.reveal_right) / 4 * 3;
int centerY = container.getHeight() / 2;
Animator animator = ViewAnimationUtils.createCircularReveal(container,
centerX, centerY,
reverse ? width : 0,
reverse ? 0 : width);
animator.setInterpolator(new FastOutSlowInInterpolator());
animator.setDuration(resources.getInteger(android.R.integer.config_mediumAnimTime));
return animator;
}
private static ValueAnimator slideAnimator(int start, int end, final View v) {
ValueAnimator animator = ValueAnimator.ofInt(start, end);
animator.setInterpolator(new FastOutSlowInInterpolator());
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
//Update Height
int value = (Integer) valueAnimator.getAnimatedValue();
ViewGroup.LayoutParams layoutParams = v.getLayoutParams();
layoutParams.height = value;
v.setLayoutParams(layoutParams);
}
});
return animator;
}
public static void showChildrenObject(final View v) {
v.setVisibility(View.VISIBLE);
ValueAnimator animator = ValueAnimator.ofFloat(0, 1f);
animator.setDuration(250);
animator.setInterpolator(new FastOutSlowInInterpolator());
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float value = ((Float) (animation.getAnimatedValue())).floatValue();
v.setAlpha(value);
v.setScaleX(value);
v.setScaleY(value);
}
});
animator.start();
}
private ValueAnimator slideAnimator(int start, int end, final View v) {
ValueAnimator animator = ValueAnimator.ofInt(start, end);
animator.setInterpolator(new FastOutSlowInInterpolator());
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
//Update Height
int value = (Integer) valueAnimator.getAnimatedValue();
ViewGroup.LayoutParams layoutParams = v.getLayoutParams();
layoutParams.height = value;
v.setLayoutParams(layoutParams);
}
});
return animator;
}
/**
* Called by worker task when decoder is ready and image size and EXIF orientation is known.
*/
private synchronized void onTilesInited(ImageRegionDecoder decoder, int sWidth, int sHeight, int sOrientation) {
// If actual dimensions don't match the declared size, reset everything.
if (this.sWidth > 0 && this.sHeight > 0 && (this.sWidth != sWidth || this.sHeight != sHeight)) {
reset(false);
if (bitmap != null) {
if (!bitmapIsCached) {
bitmap.recycle();
}
bitmap = null;
bitmapIsPreview = false;
bitmapIsCached = false;
}
}
this.decoder = decoder;
this.sWidth = sWidth;
this.sHeight = sHeight;
this.sOrientation = sOrientation;
checkReady();
checkImageLoaded();
invalidate();
requestLayout();
animate().setInterpolator(new FastOutSlowInInterpolator()).alpha(1);
}
/**
* Called by worker task when full size image bitmap is ready (tiling is disabled).
*/
private synchronized void onImageLoaded(Bitmap bitmap, int sOrientation, boolean bitmapIsCached) {
// If actual dimensions don't match the declared size, reset everything.
if (this.sWidth > 0 && this.sHeight > 0 && (this.sWidth != bitmap.getWidth() || this.sHeight != bitmap.getHeight())) {
reset(false);
}
if (this.bitmap != null && !this.bitmapIsCached) {
this.bitmap.recycle();
}
this.bitmapIsPreview = false;
this.bitmapIsCached = bitmapIsCached;
this.bitmap = bitmap;
this.sWidth = bitmap.getWidth();
this.sHeight = bitmap.getHeight();
this.sOrientation = sOrientation;
boolean ready = checkReady();
boolean imageLoaded = checkImageLoaded();
if (ready || imageLoaded) {
invalidate();
requestLayout();
}
animate().setInterpolator(new FastOutSlowInInterpolator()).alpha(1);
}
private static ValueAnimator slideAnimator(int start, int end, final View v) {
ValueAnimator animator = ValueAnimator.ofInt(start, end);
animator.setInterpolator(new FastOutSlowInInterpolator());
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
//Update Height
int value = (Integer) valueAnimator.getAnimatedValue();
ViewGroup.LayoutParams layoutParams = v.getLayoutParams();
layoutParams.height = value;
v.setLayoutParams(layoutParams);
}
});
return animator;
}
private static ValueAnimator flipAnimator(boolean isFlipped, final View v) {
if (v != null) {
ValueAnimator animator = ValueAnimator.ofFloat(isFlipped ? -1f : 1f, isFlipped ? 1f : -1f);
animator.setInterpolator(new FastOutSlowInInterpolator());
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
//Update Height
v.setScaleY((Float) valueAnimator.getAnimatedValue());
}
});
return animator;
}
return null;
}
public InkPageIndicator(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
final int density = (int) context.getResources().getDisplayMetrics().density;
final TypedArray typedArray = getContext().obtainStyledAttributes(
attrs, R.styleable.InkPageIndicator, defStyle, 0);
dotDiameter = typedArray.getDimensionPixelSize(R.styleable.InkPageIndicator_dotDiameter, DEFAULT_DOT_SIZE * density);
dotRadius = dotDiameter / 2;
halfDotRadius = dotRadius / 2;
gap = typedArray.getDimensionPixelSize(R.styleable.InkPageIndicator_dotGap, DEFAULT_GAP * density);
animDuration = (long) typedArray.getInteger(R.styleable.InkPageIndicator_animationDuration, DEFAULT_ANIM_DURATION);
animHalfDuration = animDuration / 2;
unselectedColour = typedArray.getColor(R.styleable.InkPageIndicator_pageIndicatorColor, DEFAULT_UNSELECTED_COLOUR);
int selectedColour = typedArray.getColor(R.styleable.InkPageIndicator_currentPageIndicatorColor, DEFAULT_SELECTED_COLOUR);
typedArray.recycle();
unselectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
unselectedPaint.setColor(unselectedColour);
selectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
selectedPaint.setColor(selectedColour);
interpolator = new FastOutSlowInInterpolator();
combinedUnselectedPath = new Path();
unselectedDotPath = new Path();
unselectedDotLeftPath = new Path();
unselectedDotRightPath = new Path();
rectF = new RectF();
addOnAttachStateChangeListener(this);
}
private void animateSky() {
mValueAnimator.setInterpolator(new FastOutSlowInInterpolator());
mValueAnimator.setFloatValues(0.0F, timeScale);
mValueAnimator.setDuration(3000);
mValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
timeScale = (float) valueAnimator.getAnimatedValue();
invalidate();
}
});
mValueAnimator.start();
}
public WidgetsBottomSheet(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
SettingsTheme.apply(context);
setWillNotDraw(false);
mLauncher = Launcher.getLauncher(context);
mOpenCloseAnimator = LauncherAnimUtils.ofPropertyValuesHolder(this);
mFastOutSlowInInterpolator = new FastOutSlowInInterpolator();
mScrollInterpolator = new VerticalPullDetector.ScrollInterpolator();
mInsets = new Rect();
mVerticalPullDetector = new VerticalPullDetector(context);
mVerticalPullDetector.setListener(this);
}
/**
* Animate FAB on snackbar change.
*/
private void updateFabTranslationForSnackbar(CoordinatorLayout parent, View fab,
View snackbar) {
final float translationY = getFabTranslationYForSnackbar(parent, fab);
if (translationY != this.mTranslationY) {
ViewCompat.animate(fab).cancel();
if (Math.abs(translationY - this.mTranslationY) == (float) snackbar.getHeight()) {
ViewCompat.animate(fab).translationY(translationY).setInterpolator(
new FastOutSlowInInterpolator());
} else {
fab.setTranslationY(translationY);
}
this.mTranslationY = translationY;
}
}
@Override
public void animateShow() {
targetView.animate()
.translationX(initTranslationX)
.translationY(initTranslationY)
.setInterpolator(new FastOutSlowInInterpolator())
.setDuration(animationDuration)
.start();
}
@Override
public void animateShow() {
ValueAnimator animator = ValueAnimator.ofObject(argbEvaluator, startColor, shadowBgColor);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
targetView.setBackgroundColor((Integer) animation.getAnimatedValue());
}
});
animator.setInterpolator(new FastOutSlowInInterpolator());
animator.setDuration(isZeroDuration?0:animationDuration).start();
}
@Override
public void animateDismiss() {
ValueAnimator animator = ValueAnimator.ofObject(argbEvaluator, shadowBgColor, startColor);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
targetView.setBackgroundColor((Integer) animation.getAnimatedValue());
}
});
animator.setInterpolator(new FastOutSlowInInterpolator());
animator.setDuration(isZeroDuration?0:animationDuration).start();
}
@Override
public void animateDismiss() {
targetView.animate()
.scaleX(0f)
.scaleY(0f)
.alpha(0f)
.setDuration(animationDuration)
.setInterpolator(new FastOutSlowInInterpolator())
.start();
}
@Override
public void animateDismiss() {
targetView.animate()
.translationX(startTranslationX)
.translationY(startTranslationY).alpha(0f)
.setInterpolator(new FastOutSlowInInterpolator())
.setDuration(animationDuration)
.start();
}