下面列出了android.view.animation.TranslateAnimation#setFillBefore() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
@SuppressLint("NewApi")
public static void translateY(final View view, float fromY, float toY, long duration)
{
if (Build.VERSION.SDK_INT >= 12)
{
if (duration == 0)
view.setTranslationY(toY);
else
view.animate().translationY(toY).setDuration(duration).start();
}
else
{
TranslateAnimation translate = new TranslateAnimation(0, 0, fromY, toY);
translate.setDuration(duration);
translate.setFillEnabled(true);
translate.setFillBefore(true);
translate.setFillAfter(true);
addAnimation(view, translate);
}
}
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 Animation getTranslateAnimation() {
TranslateAnimation translateAnimation = new TranslateAnimation(0, getWidth() * 2,
0, getHeight() * 2);
translateAnimation.setDuration(2000);
translateAnimation.setRepeatCount(2);
translateAnimation.setFillAfter(true);
translateAnimation.setFillBefore(false);
translateAnimation.setRepeatMode(Animation.REVERSE);
return translateAnimation;
}
private Animation getTranslateAnimation() {
TranslateAnimation translateAnimation = new TranslateAnimation(0, getWidth() * 2,
0, getHeight() * 2);
translateAnimation.setDuration(2000);
translateAnimation.setRepeatCount(2);
translateAnimation.setFillAfter(true);
translateAnimation.setFillBefore(false);
translateAnimation.setRepeatMode(Animation.REVERSE);
return translateAnimation;
}
public static void translateY(final View view, float fromY, float toY, long duration) {
if (Build.VERSION.SDK_INT >= 12) {
if (duration == 0)
view.setTranslationY(toY);
else
view.animate().translationY(toY).setDuration(duration).start();
} else {
TranslateAnimation translate = new TranslateAnimation(0, 0, fromY, toY);
translate.setDuration(duration);
translate.setFillEnabled(true);
translate.setFillBefore(true);
translate.setFillAfter(true);
addAnimation(view, translate);
}
}