下面列出了怎么用android.support.v4.view.animation.FastOutLinearInInterpolator的API类实例代码及写法,或者点击链接到github查看源代码。
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void prepareCircularReveal(View startView, FrameLayout targetView) {
int centerX = (startView.getLeft() + startView.getRight()) / 2;
// Subtract the start view's height to adjust for relative coordinates on screen.
int centerY = (startView.getTop() + startView.getBottom()) / 2 - startView.getHeight();
float endRadius = (float) Math.hypot(centerX, centerY);
mCircularReveal = ViewAnimationUtils.createCircularReveal(
targetView, centerX, centerY, startView.getWidth(), endRadius);
mCircularReveal.setInterpolator(new FastOutLinearInInterpolator());
mCircularReveal.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mIcon.setVisibility(View.GONE);
mCircularReveal.removeListener(this);
}
});
// Adding a color animation from the FAB's color to transparent creates a dissolve like
// effect to the circular reveal.
int accentColor = ContextCompat.getColor(this, mCategory.getTheme().getAccentColor());
mColorChange = ObjectAnimator.ofInt(targetView,
ViewUtils.FOREGROUND_COLOR, accentColor, Color.TRANSPARENT);
mColorChange.setEvaluator(new ArgbEvaluator());
mColorChange.setInterpolator(mInterpolator);
}
public DisappearingAnimator(boolean removeDialog) {
mIsDialogClosing = removeDialog;
Animator sheetFader = ObjectAnimator.ofFloat(
mRequestView, View.ALPHA, mRequestView.getAlpha(), 0f);
Animator sheetTranslator = ObjectAnimator.ofFloat(
mRequestView, View.TRANSLATION_Y, 0f, mAnimatorTranslation);
AnimatorSet current = new AnimatorSet();
current.setDuration(DIALOG_EXIT_ANIMATION_MS);
current.setInterpolator(new FastOutLinearInInterpolator());
if (mIsDialogClosing) {
Animator scrimFader = ObjectAnimator.ofInt(mFullContainer.getBackground(),
AnimatorProperties.DRAWABLE_ALPHA_PROPERTY, 127, 0);
current.playTogether(sheetFader, sheetTranslator, scrimFader);
} else {
current.playTogether(sheetFader, sheetTranslator);
}
mSheetAnimator = current;
mSheetAnimator.addListener(this);
mSheetAnimator.start();
}
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();
}
}
public DisappearingAnimator(boolean removeDialog) {
mIsDialogClosing = removeDialog;
Animator sheetFader = ObjectAnimator.ofFloat(
mRequestView, View.ALPHA, mRequestView.getAlpha(), 0f);
Animator sheetTranslator = ObjectAnimator.ofFloat(
mRequestView, View.TRANSLATION_Y, 0f, mAnimatorTranslation);
AnimatorSet current = new AnimatorSet();
current.setDuration(DIALOG_EXIT_ANIMATION_MS);
current.setInterpolator(new FastOutLinearInInterpolator());
if (mIsDialogClosing) {
Animator scrimFader = ObjectAnimator.ofInt(mFullContainer.getBackground(),
AnimatorProperties.DRAWABLE_ALPHA_PROPERTY, 127, 0);
current.playTogether(sheetFader, sheetTranslator, scrimFader);
} else {
current.playTogether(sheetFader, sheetTranslator);
}
mSheetAnimator = current;
mSheetAnimator.addListener(this);
mSheetAnimator.start();
}
private void updateFabTranslationForSnackbar(CoordinatorLayout parent,
SkittleContainer container, View snackbar) {
float translationY = this.getFabTranslationYForSnackbar(parent, container);
if ((translationY == -snackbar.getHeight())) {
ViewCompat.animate(container)
.translationY(-translationY)
.setInterpolator(new FastOutLinearInInterpolator())
.setListener(null);
} else if (translationY != this.mTranslationY) {
ViewCompat.animate(container).cancel();
if (Math.abs(translationY - this.mTranslationY) == (float) snackbar.getHeight()) {
ViewCompat.animate(container)
.translationY(translationY)
.setInterpolator(new FastOutLinearInInterpolator())
.setListener(null);
} else {
ViewCompat.setTranslationY(container, translationY);
}
this.mTranslationY = translationY;
}
}
private void dismissDialog() {
if (mDialogInOutAnimator != null || !isShowing()) return;
Animator dropDown =
ObjectAnimator.ofFloat(mLayout, View.TRANSLATION_Y, 0f, mLayout.getHeight());
Animator fadeOut = ObjectAnimator.ofFloat(mLayout, View.ALPHA, mLayout.getAlpha(), 0f);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(dropDown, fadeOut);
mDialogInOutAnimator = animatorSet;
mDialogInOutAnimator.setDuration(DIALOG_EXIT_ANIMATION_MS);
mDialogInOutAnimator.setInterpolator(new FastOutLinearInInterpolator());
mDialogInOutAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mDialogInOutAnimator = null;
dismiss();
}
});
mDialogInOutAnimator.start();
}
public DisappearingAnimator(boolean removeDialog) {
mIsDialogClosing = removeDialog;
Animator sheetFader = ObjectAnimator.ofFloat(
mRequestView, View.ALPHA, mRequestView.getAlpha(), 0f);
Animator sheetTranslator = ObjectAnimator.ofFloat(
mRequestView, View.TRANSLATION_Y, 0f, mAnimatorTranslation);
AnimatorSet current = new AnimatorSet();
current.setDuration(DIALOG_EXIT_ANIMATION_MS);
current.setInterpolator(new FastOutLinearInInterpolator());
if (mIsDialogClosing) {
Animator scrimFader = ObjectAnimator.ofInt(mFullContainer.getBackground(),
AnimatorProperties.DRAWABLE_ALPHA_PROPERTY, 127, 0);
current.playTogether(sheetFader, sheetTranslator, scrimFader);
} else {
current.playTogether(sheetFader, sheetTranslator);
}
mSheetAnimator = current;
mSheetAnimator.addListener(this);
mSheetAnimator.start();
}
/**
* header view 完成更新后恢复初始状态
*/
public void onHeaderRefreshComplete() {
mHeaderState = PULL_TO_REFRESH;
upAnimator = ValueAnimator.ofInt(getHeaderTopMargin(), -mHeaderViewHeight);
upAnimator.setDuration(100);
upAnimator.setInterpolator(new FastOutLinearInInterpolator());
upAnimator.start();
upAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int value = (int) animation.getAnimatedValue();
setHeaderTopMargin(value);
}
});
mHeaderImageView.setVisibility(View.VISIBLE);
mHeaderImageView.setImageResource(android.R.drawable.arrow_down_float);
mHeaderTextView.setText(R.string.pull_to_refresh_pull_label);
mHeaderProgressBar.setVisibility(View.GONE);
if (mOnHeaderRefreshListener != null) {
mOnHeaderRefreshListener.onHeaderRefreshFinished();
}
// mHeaderUpdateTextView.setText("");
}
public void updateTransition(View v) {
mDrawerListenerAdapter.removeAllTransitions();
ViewTransitionBuilder builder = ViewTransitionBuilder.transit(mGradient).translationX(-mGradient.getWidth(), 0);
switch (v.getId()) {
case R.id.interpolator_default:
break;
case R.id.interpolator_linear:
builder.interpolator(new LinearInterpolator());
break;
case R.id.interpolator_accelerate:
builder.interpolator(new AccelerateInterpolator());
break;
case R.id.interpolator_decelerate:
builder.interpolator(new DecelerateInterpolator());
break;
case R.id.interpolator_fastout:
builder.interpolator(new FastOutLinearInInterpolator());
break;
case R.id.interpolator_anticipate:
builder.interpolator(new AnticipateInterpolator());
break;
}
mDrawerListenerAdapter.addTransition(builder);
}
@Override public boolean onSingleTapUp(MotionEvent e) {
View nextView = getNext();
nextView.bringToFront();
nextView.setVisibility(View.VISIBLE);
final float finalRadius =
(float) Math.hypot(nextView.getWidth() / 2f, nextView.getHeight() / 2f) + hypo(
nextView, e);
Animator revealAnimator =
ViewAnimationUtils.createCircularReveal(nextView, (int) e.getX(), (int) e.getY(), 0,
finalRadius, View.LAYER_TYPE_HARDWARE);
revealAnimator.setDuration(MainActivity.SLOW_DURATION);
revealAnimator.setInterpolator(new FastOutLinearInInterpolator());
revealAnimator.start();
return true;
}
public RightViewHideShowAnimation(View view, boolean toVisible, long duration) {
super(false);
this.toVisible = toVisible;
this.animationView = view;
//Creates the Alpha animation for the transition
float startAlpha = toVisible ? 0 : 1;
float endAlpha = toVisible ? 1 : 0;
AlphaAnimation alphaAnimation = new AlphaAnimation(startAlpha, endAlpha);
alphaAnimation.setDuration(duration);
//Creates the Translate animation for the transition
int startX = toVisible ? getHideShowDelta(view) : 0;
int endX = toVisible ? 0 : getHideShowDelta(view);
TranslateAnimation translateAnimation = new TranslateAnimation(startX, endX, 0, 0);
translateAnimation.setInterpolator(toVisible ? new LinearOutSlowInInterpolator() : new FastOutLinearInInterpolator());
translateAnimation.setDuration(duration);
//Adds the animations to the set
addAnimation(alphaAnimation);
addAnimation(translateAnimation);
setAnimationListener(new Listener());
}
public RightViewHideShowAnimation(View view, boolean toVisible, long duration) {
super(false);
this.toVisible = toVisible;
this.animationView = view;
//Creates the Alpha animation for the transition
float startAlpha = toVisible ? 0 : 1;
float endAlpha = toVisible ? 1 : 0;
AlphaAnimation alphaAnimation = new AlphaAnimation(startAlpha, endAlpha);
alphaAnimation.setDuration(duration);
//Creates the Translate animation for the transition
int startX = toVisible ? getHideShowDelta(view) : 0;
int endX = toVisible ? 0 : getHideShowDelta(view);
TranslateAnimation translateAnimation = new TranslateAnimation(startX, endX, 0, 0);
translateAnimation.setInterpolator(toVisible ? new LinearOutSlowInInterpolator() : new FastOutLinearInInterpolator());
translateAnimation.setDuration(duration);
//Adds the animations to the set
addAnimation(alphaAnimation);
addAnimation(translateAnimation);
setAnimationListener(new Listener());
}
private void changeVisibility() {
View music_info_cardView = findViewById(R.id.music_info_cardView);
View control_layout = findViewById(R.id.control_layout);
View seekbar_layout = findViewById(R.id.seekbar_layout);
View lrcView = findViewById(R.id.other_lrc_view);
View gradient = findViewById(R.id.gradient);
View gradient_bottom = findViewById(R.id.gradient_bottom);
View gradient_top = findViewById(R.id.gradient_top);
TransitionManager.beginDelayedTransition(transitionsContainer, new TransitionSet().addTransition(new Fade()).setInterpolator(visible ? new LinearOutSlowInInterpolator() : new FastOutLinearInInterpolator()));
if (music_info_cardView.getVisibility() == VISIBLE) {
music_info_cardView.setVisibility(GONE);
control_layout.setVisibility(GONE);
seekbar_layout.setVisibility(GONE);
lrcView.setVisibility(VISIBLE);
gradient.setVisibility(VISIBLE);
gradient_bottom.setVisibility(VISIBLE);
gradient_top.setVisibility(VISIBLE);
} else {
music_info_cardView.setVisibility(VISIBLE);
control_layout.setVisibility(VISIBLE);
seekbar_layout.setVisibility(VISIBLE);
lrcView.setVisibility(GONE);
gradient.setVisibility(GONE);
gradient_bottom.setVisibility(GONE);
gradient_top.setVisibility(GONE);
}
visible = !visible;
}
private void animateOutFrameDetails() {
ViewUtils.onLaidOut(frameDetails, new Runnable() {
@Override
public void run() {
if (!frameDetails.isShown()) {
return;
}
ObjectAnimator alpha = ObjectAnimator.ofFloat(frameDetails, View.ALPHA, 1f, 0f);
ObjectAnimator translate = ofFloat(frameDetails, View.TRANSLATION_Y, 0f, frameDetails.getHeight() * 0.3f);
AnimatorSet set = new AnimatorSet();
set.playTogether(alpha, translate);
set.setDuration(ANIM_DURATION);
set.setInterpolator(new FastOutLinearInInterpolator());
set.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
frameDetails.setAlpha(1f);
frameDetails.setTranslationY(0);
frameDetails.setVisibility(View.GONE);
}
});
set.start();
}
});
}
public void slideInFab() {
if (mAnimatingFab) {
return;
}
if (isFabExpanded()) {
contractFab();
return;
}
ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mFab.getLayoutParams();
float dy = mFab.getHeight() + lp.bottomMargin;
if (mFab.getTranslationY() != dy) {
return;
}
mAnimatingFab = true;
mFab.setVisibility(View.VISIBLE);
mFab.animate()
.setStartDelay(0)
.setDuration(200)
.setInterpolator(new FastOutLinearInInterpolator())
.translationY(0f)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(final Animator animation) {
super.onAnimationEnd(animation);
mAnimatingFab = false;
}
})
.start();
}
public void slideOutFab() {
if (mAnimatingFab) {
return;
}
if (isFabExpanded()) {
contractFab();
return;
}
ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mFab.getLayoutParams();
if (mFab.getTranslationY() != 0f) {
return;
}
mAnimatingFab = true;
mFab.animate()
.setStartDelay(0)
.setDuration(200)
.setInterpolator(new FastOutLinearInInterpolator())
.translationY(mFab.getHeight() + lp.bottomMargin)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(final Animator animation) {
super.onAnimationEnd(animation);
mAnimatingFab = false;
mFab.setVisibility(View.INVISIBLE);
}
})
.start();
}
public void slideInFab() {
if (mAnimatingFab) {
return;
}
if (isFabExpanded()) {
contractFab();
return;
}
ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mFab.getLayoutParams();
float dy = mFab.getHeight() + lp.bottomMargin;
if (mFab.getTranslationY() != dy) {
return;
}
mAnimatingFab = true;
mFab.setVisibility(View.VISIBLE);
mFab.animate()
.setStartDelay(0)
.setDuration(200)
.setInterpolator(new FastOutLinearInInterpolator())
.translationY(0f)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(final Animator animation) {
super.onAnimationEnd(animation);
mAnimatingFab = false;
}
})
.start();
}
public void slideOutFab() {
if (mAnimatingFab) {
return;
}
if (isFabExpanded()) {
contractFab();
return;
}
ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mFab.getLayoutParams();
if (mFab.getTranslationY() != 0f) {
return;
}
mAnimatingFab = true;
mFab.animate()
.setStartDelay(0)
.setDuration(200)
.setInterpolator(new FastOutLinearInInterpolator())
.translationY(mFab.getHeight() + lp.bottomMargin)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(final Animator animation) {
super.onAnimationEnd(animation);
mAnimatingFab = false;
mFab.setVisibility(View.INVISIBLE);
}
})
.start();
}
private void initUi() {
fab_1 = (FloatingMenuButton) findViewById(R.id.fab_1);
fab_1.setStartAngle(0)
.setEndAngle(360)
.setRadius(200)
.setAnimationType(AnimationType.EXPAND)
.setMovementStyle(MovementStyle.STICKED_TO_SIDES);
fab_1.getAnimationHandler()
.setOpeningAnimationDuration(500)
.setClosingAnimationDuration(200)
.setLagBetweenItems(0)
.setOpeningInterpolator(new FastOutSlowInInterpolator())
.setClosingInterpolator(new FastOutLinearInInterpolator())
.shouldFade(true)
.shouldScale(true)
.shouldRotate(false);
fab_2 = (FloatingMenuButton) findViewById(R.id.fab_2);
fab_2.setStartAngle(0)
.setEndAngle(360)
.setTransparentAfterMilliseconds(0)
.setAnimationType(AnimationType.RADIAL)
.setMovementStyle(MovementStyle.FREE);
fab_2.getAnimationHandler()
.setOpeningAnimationDuration(500)
.setClosingAnimationDuration(200)
.setLagBetweenItems(0)
.setOpeningInterpolator(new FastOutSlowInInterpolator())
.setClosingInterpolator(new FastOutLinearInInterpolator())
.shouldFade(true)
.shouldScale(true)
.shouldRotate(false);
}
@SuppressWarnings("ConstantConditions")
private void setAvatarDrawable(AvatarView avatarView) {
Player player = PreferencesHelper.getPlayer(getActivity());
avatarView.setAvatar(player.getAvatar().getDrawableId());
ViewCompat.animate(avatarView)
.setInterpolator(new FastOutLinearInInterpolator())
.setStartDelay(500)
.scaleX(1)
.scaleY(1)
.start();
}
private void initInterpolations() {
Class[] interpolations = {
FastOutSlowInInterpolator.class,
BounceInterpolator.class,
LinearInterpolator.class,
DecelerateInterpolator.class,
CycleInterpolator.class,
AnticipateInterpolator.class,
AccelerateDecelerateInterpolator.class,
AccelerateInterpolator.class,
AnticipateOvershootInterpolator.class,
FastOutLinearInInterpolator.class,
LinearOutSlowInInterpolator.class,
OvershootInterpolator.class};
try {
interpolatorText = (Interpolator) interpolations[animateTextsEnter].newInstance();
interpolatorDrawablesEnter = (Interpolator) interpolations[animateDrawablesEnter].newInstance();
interpolatorSelector = (Interpolator) interpolations[animateSelector].newInstance();
interpolatorTextExit = (Interpolator) interpolations[animateTextsExit].newInstance();
interpolatorDrawablesExit = (Interpolator) interpolations[animateDrawablesExit].newInstance();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Creates interpolator.
*
* @param interpolatorType
* @return
*/
public static TimeInterpolator createInterpolator(@IntRange(from = 0, to = 10) final int interpolatorType) {
switch (interpolatorType) {
case ACCELERATE_DECELERATE_INTERPOLATOR:
return new AccelerateDecelerateInterpolator();
case ACCELERATE_INTERPOLATOR:
return new AccelerateInterpolator();
case ANTICIPATE_INTERPOLATOR:
return new AnticipateInterpolator();
case ANTICIPATE_OVERSHOOT_INTERPOLATOR:
return new AnticipateOvershootInterpolator();
case BOUNCE_INTERPOLATOR:
return new BounceInterpolator();
case DECELERATE_INTERPOLATOR:
return new DecelerateInterpolator();
case FAST_OUT_LINEAR_IN_INTERPOLATOR:
return new FastOutLinearInInterpolator();
case FAST_OUT_SLOW_IN_INTERPOLATOR:
return new FastOutSlowInInterpolator();
case LINEAR_INTERPOLATOR:
return new LinearInterpolator();
case LINEAR_OUT_SLOW_IN_INTERPOLATOR:
return new LinearOutSlowInInterpolator();
case OVERSHOOT_INTERPOLATOR:
return new OvershootInterpolator();
default:
return new LinearInterpolator();
}
}
public BottomViewHideShowAnimation(View view, boolean toVisible, long duration) {
super(false);
this.toVisible = toVisible;
this.animationView = view;
//Creates the Alpha animation for the transition
float startAlpha = toVisible ? 0 : 1;
float endAlpha = toVisible ? 1 : 0;
AlphaAnimation alphaAnimation = new AlphaAnimation(startAlpha, endAlpha);
alphaAnimation.setDuration(duration);
//Creates the Translate animation for the transition
int startY = toVisible ? getHideShowDelta(view) : 0;
int endY = toVisible ? 0 : getHideShowDelta(view);
TranslateAnimation translateAnimation = new TranslateAnimation(0, 0, startY, endY);
translateAnimation.setInterpolator(toVisible ? new LinearOutSlowInInterpolator() : new FastOutLinearInInterpolator());
translateAnimation.setDuration(duration);
//Adds the animations to the set
addAnimation(alphaAnimation);
addAnimation(translateAnimation);
setAnimationListener(new Listener());
}
public TopViewHideShowAnimation(View view, boolean toVisible, long duration) {
super(false);
this.toVisible = toVisible;
this.animationView = view;
//Creates the Alpha animation for the transition
float startAlpha = toVisible ? 0 : 1;
float endAlpha = toVisible ? 1 : 0;
AlphaAnimation alphaAnimation = new AlphaAnimation(startAlpha, endAlpha);
alphaAnimation.setDuration(duration);
//Creates the Translate animation for the transition
int startY = toVisible ? -view.getHeight() : 0;
int endY = toVisible ? 0 : -view.getHeight();
TranslateAnimation translateAnimation = new TranslateAnimation(0, 0, startY, endY);
translateAnimation.setInterpolator(toVisible ? new LinearOutSlowInInterpolator() : new FastOutLinearInInterpolator());
translateAnimation.setDuration(duration);
//Adds the animations to the set
addAnimation(alphaAnimation);
addAnimation(translateAnimation);
setAnimationListener(new Listener());
}
private void startAnimatorBy(float from, float to, int duration) {
cancelAndClearAnimator();
// Animate the circle
mAnimator = ObjectAnimator.ofFloat(this, RADIUS_PROPERTY, from, to);
mAnimator.setInterpolator(new FastOutLinearInInterpolator());
mAnimator.setDuration(duration);
mAnimator.start();
}
private void executeCardsSequentialAnimation() {
final int length = cardsLine.getChildCount();
cardsLine.setVisibility(View.VISIBLE);
final Animator[] animators = new Animator[length];
for (int i = 0; i < length; i++) {
View target = cardsLine.getChildAt(i);
final float x0 = 0;// i == 0 ? 0 : -10 * (1 + i * 0.2f);
final float y0 = 10 * i;
target.setTranslationX(x0);
target.setTranslationY(y0);
AnimatorPath path = new AnimatorPath();
path.moveTo(x0, y0);
path.lineTo(0, 0);
PathPoint[] points = new PathPoint[path.getPoints().size()];
path.getPoints().toArray(points);
AnimatorSet set = new AnimatorSet();
set.play(ObjectAnimator.ofObject(target, PATH_POINT, new PathEvaluator(), points))
.with(ObjectAnimator.ofFloat(target, View.ALPHA, 0.8f, 1f));
animators[i] = set;
animators[i].setStartDelay(15 * i);
}
final AnimatorSet sequential = new AnimatorSet();
sequential.playTogether(animators);
sequential.setInterpolator(new FastOutLinearInInterpolator());
sequential.setDuration(FAST_DURATION);
sequential.start();
}
public AnimationHelper(ViewHelper viewHelper) {
this.viewHelper = viewHelper;
fabAnimInterpolator = new AccelerateDecelerateInterpolator();
revealAnimInterpolator = new FastOutLinearInInterpolator();
}