下面列出了android.view.animation.ScaleAnimation#setInterpolator() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Hides the FAB.
*/
@Override
public void hide() {
// Only use scale animation if FAB is visible
if (getVisibility() == View.VISIBLE) {
// Pivots indicate where the animation begins from
float pivotX = getPivotX() + getTranslationX();
float pivotY = getPivotY() + getTranslationY();
// Animate FAB shrinking
ScaleAnimation anim = new ScaleAnimation(1, 0, 1, 0, pivotX, pivotY);
anim.setDuration(FAB_ANIM_DURATION);
anim.setInterpolator(getInterpolator());
startAnimation(anim);
}
setVisibility(View.INVISIBLE);
}
/**
* Hides the FAB.
*/
@Override
public void hide() {
// Only use scale animation if FAB is visible
if (getVisibility() == View.VISIBLE) {
// Pivots indicate where the animation begins from
float pivotX = getPivotX() + getTranslationX();
float pivotY = getPivotY() + getTranslationY();
// Animate FAB shrinking
ScaleAnimation anim = new ScaleAnimation(1, 0, 1, 0, pivotX, pivotY);
anim.setDuration(FAB_ANIM_DURATION);
anim.setInterpolator(getInterpolator());
startAnimation(anim);
}
setVisibility(View.INVISIBLE);
}
/**
* Hides the FAB.
*/
@Override
public void hide() {
// Only use scale animation if FAB is visible
if (getVisibility() == View.VISIBLE) {
// Pivots indicate where the animation begins from
float pivotX = getPivotX() + getTranslationX();
float pivotY = getPivotY() + getTranslationY();
// Animate FAB shrinking
ScaleAnimation anim = new ScaleAnimation(1, 0, 1, 0, pivotX, pivotY);
anim.setDuration(FAB_ANIM_DURATION);
anim.setInterpolator(getInterpolator());
startAnimation(anim);
}
setVisibility(View.INVISIBLE);
}
/**
* 中间的View动画播放
*/
private void playCenter() {
AnimationSet animationSet = new AnimationSet(false);
ScaleAnimation scaleSmall = new ScaleAnimation(1.0f, 0.6f, 1.0f, 0.6f,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
ScaleAnimation scaleBig = new ScaleAnimation(1.0f, 5.0f/3, 1.0f, 5.0f/3,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleBig.setDuration(2*1000);
scaleBig.setInterpolator(interpolator);
scaleSmall.setDuration(2*1000);
scaleSmall.setStartOffset(2*1000);
scaleSmall.setRepeatCount(-1);
scaleSmall.setFillEnabled(true);
scaleSmall.setFillAfter(true);
scaleBig.setStartOffset(2*1000);
scaleBig.setRepeatCount(-1);
scaleBig.setFillEnabled(true);
scaleBig.setFillAfter(true);
scaleSmall.setInterpolator(interpolator);
animationSet.addAnimation(scaleBig);
animationSet.addAnimation(scaleSmall);
center.startAnimation(animationSet);
}
public static Animation createScaleAnimation(View view, int parentWidth, int parentHeight,
int toX, int toY) {
// Difference in X and Y
final int diffX = toX - view.getLeft();
final int diffY = toY - view.getTop();
// Calculate actual distance using pythagors
float diffDistance = FloatMath.sqrt((toX * toX) + (toY * toY));
float parentDistance = FloatMath
.sqrt((parentWidth * parentWidth) + (parentHeight * parentHeight));
ScaleAnimation scaleAnimation = new ScaleAnimation(1f, 0f, 1f, 0f, Animation.ABSOLUTE,
diffX,
Animation.ABSOLUTE, diffY);
scaleAnimation.setFillAfter(true);
scaleAnimation.setInterpolator(new DecelerateInterpolator());
scaleAnimation.setDuration(Math.round(diffDistance / parentDistance
* Constants.SCALE_ANIMATION_DURATION_FULL_DISTANCE));
return scaleAnimation;
}
public static void zoomInView(final View view) {
if (view == null) {
return;
}
if (view.getVisibility() != View.VISIBLE) {
ScaleAnimation scaleAnimation = new ScaleAnimation(0, 1f, 0, 1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(150);
scaleAnimation.setInterpolator(MaterialInterpolator.getInstance());
view.clearAnimation();
view.startAnimation(scaleAnimation);
view.setVisibility(View.VISIBLE);
}
}
public static void scale(View view, int fromX, int toX, int fromY, int toY, int duration, Interpolator interpolator) {
ScaleAnimation animation = new ScaleAnimation(fromX, toX, fromY, toY);
animation.setDuration(duration);
animation.setFillAfter(true);
animation.setInterpolator(interpolator);
view.startAnimation(animation);
}
@Override
public void display(@NonNull SketchView sketchView, @NonNull Drawable newDrawable) {
ScaleAnimation scaleAnimation = new ScaleAnimation(fromX, 1.0f, fromY, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setInterpolator(interpolator);
scaleAnimation.setDuration(duration);
sketchView.clearAnimation();
sketchView.setImageDrawable(newDrawable);
sketchView.startAnimation(scaleAnimation);
}
public static void ScaleUpDowm(View view) {
ScaleAnimation animation = new ScaleAnimation(1.0f, 1.0f, 0.0f, 1.0f);
animation.setRepeatCount(-1);
animation.setRepeatMode(Animation.RESTART);
animation.setInterpolator(new LinearInterpolator());
animation.setDuration(1200);
view.startAnimation(animation);
}
static Animation makeOpenCloseAnimation(Context context, float startScale, float endScale, float startAlpha, float endAlpha) {
AnimationSet set = new AnimationSet(false);
ScaleAnimation scale = new ScaleAnimation(startScale, endScale, startScale, endScale, 1, 0.5f, 1, 0.5f);
scale.setInterpolator(DECELERATE_QUINT);
scale.setDuration(220);
set.addAnimation(scale);
AlphaAnimation alpha = new AlphaAnimation(startAlpha, endAlpha);
alpha.setInterpolator(DECELERATE_CUBIC);
alpha.setDuration(220);
set.addAnimation(alpha);
return set;
}
private void hideListView() {
if (!readyToHide || animationInProgress || scrollInProgress || !listViewIsShown || adapter == null) return;
readyToHide = false;
animationInProgress = true;
listView.setEnabled(false);
this.setVisibility(View.INVISIBLE);
this.pickerBox.onSelect(adapter.getItem(selectedItem), selectedItem);
AlphaAnimation hideAnimation = new AlphaAnimation(1f, 0f);
hideAnimation.setStartOffset(subScrollDuration);
hideAnimation.setDuration(200);
hideAnimation.setInterpolator(new DecelerateInterpolator());
hideAnimation.setAnimationListener(new AnimationListenerAdapter() {
@Override
public void onAnimationEnd(Animation animation) {
listViewIsShown = false;
animationInProgress = false;
}
});
DSListView.this.startAnimation(hideAnimation);
// Scale picker box text animation if animations enabled
if (selectorAnimationsEnabled && null != this.pickerBox) {
ScaleAnimation scaleAnimation = new ScaleAnimation(1f + scaleFactorDelta, 1f, 1f + scaleFactorDelta, 1f,
Animation.RELATIVE_TO_SELF, selectorAnimationCenterPivot ? 0.5f : 0f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setInterpolator(new DecelerateInterpolator());
scaleAnimation.setStartOffset(100 + subScrollDuration);
scaleAnimation.setDuration(100);
scaleAnimation.setFillAfter(true);
this.pickerBox.getCellRoot().startAnimation(scaleAnimation);
}
}
private void showListView() {
if (animationInProgress || scrollInProgress || listViewIsShown) return;
listView.setEnabled(true);
animationInProgress = true;
this.setVisibility(View.VISIBLE);
this.bringToFront();
this.readyToHide = false;
// Scale picker box if animations enabled
if (selectorAnimationsEnabled && null != this.pickerBox) {
ScaleAnimation scaleAnimation = new ScaleAnimation(1f, 1f + scaleFactorDelta, 1f, 1f + scaleFactorDelta,
Animation.RELATIVE_TO_SELF, selectorAnimationCenterPivot ? 0.5f : 0f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setInterpolator(new AccelerateInterpolator());
scaleAnimation.setDuration(100);
scaleAnimation.setFillAfter(true);
this.pickerBox.getCellRoot().startAnimation(scaleAnimation);
}
// Show picker view animation
AlphaAnimation showAnimation = new AlphaAnimation(0f, 1f);
showAnimation.setDuration(200);
showAnimation.setInterpolator(new AccelerateInterpolator());
showAnimation.setAnimationListener(new AnimationListenerAdapter() {
@Override
public void onAnimationEnd(Animation animation) {
animationInProgress = false;
listViewIsShown = true;
hideListView();
}
});
this.startAnimation(showAnimation);
}
static Animation makeOpenCloseAnimation(Context context, float startScale,
float endScale, float startAlpha, float endAlpha) {
AnimationSet set = new AnimationSet(false);
ScaleAnimation scale = new ScaleAnimation(startScale, endScale, startScale, endScale,
Animation.RELATIVE_TO_SELF, .5f, Animation.RELATIVE_TO_SELF, .5f);
scale.setInterpolator(DECELERATE_QUINT);
scale.setDuration(ANIM_DUR);
set.addAnimation(scale);
AlphaAnimation alpha = new AlphaAnimation(startAlpha, endAlpha);
alpha.setInterpolator(DECELERATE_CUBIC);
alpha.setDuration(ANIM_DUR);
set.addAnimation(alpha);
return set;
}
private void animateAltitudeBars(ImageView[] views, float[] displayValues) {
for(int v =0; v < views.length;v++) {
views[v].setMaxHeight(_view.getHeight());
ScaleAnimation scale = new ScaleAnimation(1, 1, _prevValues[v], displayValues[v], Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 1.0f);
scale.setFillAfter(true);
scale.setDuration(500);
scale.setInterpolator(new AccelerateInterpolator(1.0f));
views[v].startAnimation(scale);
}
_prevValues = displayValues;
}
public Animation createAnimation() {
ScaleAnimation anim = new ScaleAnimation(fromXScale, toXScale, fromYScale, toYScale, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
anim.setFillAfter(true);
anim.setInterpolator(new AccelerateInterpolator());
anim.setDuration(duration);
return anim;
}
/**
* start button: control button handler FAB
*/
private void initControlBtnHandler() {
final ScaleAnimation anim = new ScaleAnimation(0, 1, 0, 1);
anim.setFillBefore(true);
anim.setFillAfter(true);
anim.setFillEnabled(true);
anim.setDuration(300);
anim.setInterpolator(new OvershootInterpolator());
controlBtn.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
if (isMenuVisible()) {
setMenuVisible(false);
sideBarMenuVP.setVisibility(View.INVISIBLE);
favourBtn.setVisibility(View.INVISIBLE);
settingsBtn.setVisibility(View.INVISIBLE);
controlBtn.setImageResource(R.drawable.ic_keyboard_arrow_up_white_24dp);
controlBtn.startAnimation(anim);
} else {
setMenuVisible(true);
sideBarMenuVP.setVisibility(View.VISIBLE);
favourBtn.setVisibility(View.VISIBLE);
settingsBtn.setVisibility(View.VISIBLE);
controlBtn.setImageResource(R.drawable.ic_keyboard_arrow_down_white_24dp);
controlBtn.startAnimation(anim);
}
}
});
}
static Animation makeOpenCloseAnimation(Context context, float startScale,
float endScale, float startAlpha, float endAlpha) {
AnimationSet set = new AnimationSet(false);
ScaleAnimation scale = new ScaleAnimation(startScale, endScale, startScale, endScale,
Animation.RELATIVE_TO_SELF, .5f, Animation.RELATIVE_TO_SELF, .5f);
scale.setInterpolator(DECELERATE_QUINT);
scale.setDuration(ANIM_DUR);
set.addAnimation(scale);
AlphaAnimation alpha = new AlphaAnimation(startAlpha, endAlpha);
alpha.setInterpolator(DECELERATE_CUBIC);
alpha.setDuration(ANIM_DUR);
set.addAnimation(alpha);
return set;
}
public static void demoteView(final View view, boolean isAnimated) {
if (view == null) {
return;
}
if (isAnimated) {
ScaleAnimation scaleAnimation = new ScaleAnimation(1.1f, 1.0f, 1.1f, 1.0f, Animation.RELATIVE_TO_SELF, (float) 0.5, Animation.RELATIVE_TO_SELF, (float) 0.5);
scaleAnimation.setDuration(isAnimated ? 150 : 0);
scaleAnimation.setInterpolator(MaterialInterpolator.getInstance());
scaleAnimation.setFillAfter(true);
view.clearAnimation();
view.startAnimation(scaleAnimation);
}
}
static Animation makeOpenCloseAnimation(Context context, float startScale,
float endScale, float startAlpha, float endAlpha) {
AnimationSet set = new AnimationSet(false);
ScaleAnimation scale = new ScaleAnimation(startScale, endScale, startScale, endScale,
Animation.RELATIVE_TO_SELF, .5f, Animation.RELATIVE_TO_SELF, .5f);
scale.setInterpolator(DECELERATE_QUINT);
scale.setDuration(ANIM_DUR);
set.addAnimation(scale);
AlphaAnimation alpha = new AlphaAnimation(startAlpha, endAlpha);
alpha.setInterpolator(DECELERATE_CUBIC);
alpha.setDuration(ANIM_DUR);
set.addAnimation(alpha);
return set;
}
static Animation makeOpenCloseAnimation(Context context, float startScale,
float endScale, float startAlpha, float endAlpha) {
AnimationSet set = new AnimationSet(false);
ScaleAnimation scale = new ScaleAnimation(startScale, endScale, startScale, endScale,
Animation.RELATIVE_TO_SELF, .5f, Animation.RELATIVE_TO_SELF, .5f);
scale.setInterpolator(DECELERATE_QUINT);
scale.setDuration(ANIM_DUR);
set.addAnimation(scale);
AlphaAnimation alpha = new AlphaAnimation(startAlpha, endAlpha);
alpha.setInterpolator(DECELERATE_CUBIC);
alpha.setDuration(ANIM_DUR);
set.addAnimation(alpha);
return set;
}