下面列出了android.view.animation.TranslateAnimation#setAnimationListener() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static void hideViewFromBottom(final View view) {
if (view.getVisibility() == View.INVISIBLE) {
return;
}
int height = view.getHeight();
TranslateAnimation translateAnimation = new TranslateAnimation(Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0, Animation.ABSOLUTE, height);
translateAnimation.setDuration(ANIMATION_DURATION);
translateAnimation.setInterpolator(sAnimationInterpolator);
translateAnimation.setAnimationListener(new AnimationAdapter() {
@Override
public void onAnimationEnd(Animation animation) {
view.setVisibility(View.INVISIBLE);
}
});
view.startAnimation(translateAnimation);
}
public void animateToNext() {
et.setEnabled(false);
int totalWidth = getWidth();
int dvWidth = dv.getWidth();
int animDistance = (totalWidth - dvWidth) / 2 + dvWidth;
TranslateAnimation animOut = new TranslateAnimation(0, -animDistance, 0, 0);
animOut.setInterpolator(new AccelerateDecelerateInterpolator());
animOut.setFillAfter(true);
animOut.setDuration(AnimDuration);
TranslateAnimation animIn = new TranslateAnimation(animDistance, 0, 0, 0);
animIn.setInterpolator(new AccelerateDecelerateInterpolator());
animIn.setFillBefore(true);
animIn.setDuration(AnimDuration);
animIn.setAnimationListener(animateToNextListener);
dvNew.setVisibility(View.VISIBLE);
dv.startAnimation(animOut);
dvNew.startAnimation(animIn);
}
private void bounceBackHeader(){
int yTranslate = state == State.REFRESHING ?
header.getHeight() - headerContainer.getHeight() :
-headerContainer.getHeight() - headerContainer.getTop();
bounceAnimation = new TranslateAnimation(
TranslateAnimation.ABSOLUTE, 0,
TranslateAnimation.ABSOLUTE, 0,
TranslateAnimation.ABSOLUTE, 0,
TranslateAnimation.ABSOLUTE, yTranslate);
bounceAnimation.setDuration(BOUNCE_ANIMATION_DURATION);
bounceAnimation.setFillEnabled(true);
bounceAnimation.setFillAfter(false);
bounceAnimation.setFillBefore(true);
//bounceAnimation.setInterpolator(new OvershootInterpolator(BOUNCE_OVERSHOOT_TENSION));
bounceAnimation.setAnimationListener(new HeaderAnimationListener(yTranslate));
startAnimation(bounceAnimation);
}
private void startAnim() {
this.isPlayingAnim = true;
int distance = this.mLine.getMeasuredWidth() - this.mCircle.getMeasuredWidth();
TranslateAnimation anim = new TranslateAnimation(0.0f, this.isChecked ? (float) (-distance) : (float) distance, 0.0f, 0.0f);
anim.setDuration(40);
anim.setFillAfter(false);
anim.setAnimationListener(this);
this.mCircle.startAnimation(anim);
}
/**
* Creates animation for the gallery and homePage Icons with up direction.
*/
public void createIconUpAnimation(float dy, int delay) {
iconUpAnimation = new TranslateAnimation(0, 0, 0, (-(scale * 67.3f) + 0.5f - (dy * scale)) * iconDirection);
iconUpAnimation.setDuration(250);
iconUpAnimation.setFillAfter(false);
iconUpAnimation.setStartOffset(delay);
iconUpAnimation.setAnimationListener(iconUpAnimationListener);
}
/**
* Creates animation for the gallery and homePage Icons with down direction.
*/
public void createIconDownAnimation(float dy) {
iconDownAnimation = new TranslateAnimation(0, 0, 0, ((scale * 67.3f) + 0.5f + (dy * scale)) * iconDirection);
iconDownAnimation.setDuration(250);
iconDownAnimation.setFillAfter(false);
iconDownAnimation.setAnimationListener(iconDownAnimationListener);
}
/**
* Creates animation for the gallery and homePage Icons with up direction.
*/
public void createIconUpAnimation(float dy, int delay) {
iconUpAnimation = new TranslateAnimation(0, 0, 0, (-(scale * 67.3f) + 0.5f - (dy * scale)) * iconDirection);
iconUpAnimation.setDuration(250);
iconUpAnimation.setFillAfter(false);
iconUpAnimation.setStartOffset(delay);
iconUpAnimation.setAnimationListener(iconUpAnimationListener);
}
/**
* Creates animation for the gallery and homePage Icons with down direction.
*/
public void createIconDownAnimation(float dy) {
iconDownAnimation = new TranslateAnimation(0, 0, 0, ((scale * 67.3f) + 0.5f + (dy * scale)) * iconDirection);
iconDownAnimation.setDuration(250);
iconDownAnimation.setFillAfter(false);
iconDownAnimation.setAnimationListener(iconDownAnimationListener);
}
/**
* Creates animation for the gallery and gallery, homePage and trailer Icons with up direction.
*/
public void createIconUpAnimation(float dy, int delay) {
iconUpAnimation = new TranslateAnimation(0, 0, 0, (-(scale * 67.3f) + 0.5f - (dy * scale)) * iconDirection);
iconUpAnimation.setDuration(250);
iconUpAnimation.setFillAfter(false);
iconUpAnimation.setStartOffset(delay);
iconUpAnimation.setAnimationListener(iconUpAnimationListener);
}
/**
* Creates animation for the gallery, homePage and trailer Icons with down direction.
*/
public void createIconDownAnimation(float dy) {
iconDownAnimation = new TranslateAnimation(0, 0, 0, ((scale * 67.3f) + 0.5f + (dy * scale)) * iconDirection);
iconDownAnimation.setDuration(250);
iconDownAnimation.setFillAfter(false);
iconDownAnimation.setAnimationListener(iconDownAnimationListener);
}