下面列出了android.view.animation.TranslateAnimation#setFillAfter() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void translate(View v){
//����ƽ�Ʋ��䶯��
// TranslateAnimation ta = new TranslateAnimation(-100, 100, -50, 50);
ta = new TranslateAnimation(Animation.RELATIVE_TO_SELF, -3, Animation.RELATIVE_TO_SELF, 3,
Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
//���ö�������ʱ��
ta.setDuration(2000);
//�����ظ����Ŵ���
ta.setRepeatCount(1);
//�����ظ�����ģʽ
ta.setRepeatMode(Animation.REVERSE);
//���ö���ͣ���ڽ���λ��
ta.setFillAfter(true);
iv.startAnimation(ta);
}
/**
* Translates the adapter in Y
*
* @param of offset in px
*/
public void translateHeader(float of) {
float ofCalculated = of * mScrollMultiplier;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && of < mHeader.getHeight()) {
mHeader.setTranslationY(ofCalculated);
} else if (of < mHeader.getHeight()) {
TranslateAnimation anim = new TranslateAnimation(0, 0, ofCalculated, ofCalculated);
anim.setFillAfter(true);
anim.setDuration(0);
mHeader.startAnimation(anim);
}
mHeader.setClipY(Math.round(ofCalculated));
if (mParallaxScroll != null) {
final RecyclerView.ViewHolder holder = mRecyclerView.findViewHolderForAdapterPosition(0);
float left;
if (holder != null) {
left = Math.min(1, ((ofCalculated) / (mHeader.getHeight() * mScrollMultiplier)));
}else {
left = 1;
}
mParallaxScroll.onParallaxScroll(left, of, mHeader);
}
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
protected void translateTo(final int translationY) {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB) {
final TranslateAnimation anim = new TranslateAnimation(0, 0, translationY, translationY);
anim.setFillAfter(true);
anim.setDuration(0);
quickReturnView.startAnimation(anim);
} else {
quickReturnView.setTranslationY(translationY);
}
}
public static TranslateAnimation getPortraitTranslateAnimation(int start, int end, int durationMillis) {
TranslateAnimation translateAnimation = new TranslateAnimation(0.0F, 0.0F, (float) start, (float) end);
translateAnimation.setDuration((long) durationMillis);
translateAnimation.setFillEnabled(true);
translateAnimation.setFillAfter(true);
return translateAnimation;
}
/**
* 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);
}
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);
}
}
/**
* 位移 Translate
*/
public static Animation getTranslateAnimation(float fromXDelta,
float toXDelta, float fromYDelta, float toYDelta,
long durationMillis) {
TranslateAnimation translate = new TranslateAnimation(fromXDelta,
toXDelta, fromYDelta, toYDelta);
translate.setDuration(durationMillis);
translate.setFillAfter(true);
return translate;
}
private TranslateAnimation createTranslateAnimation(Point oldOffset, Point newOffset) {
TranslateAnimation translate = new TranslateAnimation(Animation.ABSOLUTE, oldOffset.x,
Animation.ABSOLUTE, newOffset.x,
Animation.ABSOLUTE, oldOffset.y,
Animation.ABSOLUTE, newOffset.y);
translate.setDuration(ANIMATION_DURATION);
translate.setFillEnabled(true);
translate.setFillAfter(true);
translate.setInterpolator(new AccelerateDecelerateInterpolator());
return translate;
}
public static void translate(View view, int startX, int startY, int endX, int endY, int duration, Interpolator interpolator) {
TranslateAnimation animation = new TranslateAnimation(startX, endX, startY, endY);
animation.setDuration(duration);
animation.setFillAfter(true);
animation.setInterpolator(interpolator);
view.startAnimation(animation);
}
/**
* 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);
}
private TranslateAnimation generateTranslateAnim(BarrageItem item, int leftMargin) {
TranslateAnimation anim = new TranslateAnimation(leftMargin, -item.textMeasuredWidth, 0, 0);
anim.setDuration(item.moveSpeed);
anim.setInterpolator(new AccelerateDecelerateInterpolator());
anim.setFillAfter(true);
return anim;
}
protected final void translateChild(View v, Point prev, Point now) {
TranslateAnimation translate = new TranslateAnimation(Animation.ABSOLUTE, -now.x + prev.x, Animation.ABSOLUTE, 0, Animation.ABSOLUTE, -now.y
+ prev.y, Animation.ABSOLUTE, 0);
translate.setInterpolator(new AccelerateInterpolator(4f));
translate.setDuration(350);
translate.setFillEnabled(false);
translate.setFillAfter(false);
v.clearAnimation();
v.startAnimation(translate);
}
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);
}
private void initIconAnimation(View view, int delay) {
TranslateAnimation ta=new TranslateAnimation(Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,0f,
Animation.RELATIVE_TO_PARENT,1f,Animation.RELATIVE_TO_SELF,0f);
ta.setDuration(1000);
ta.setStartOffset(delay);
ta.setFillAfter(true);
view.startAnimation(ta);
}
@Override
protected void translatePreICS(View view, float offset) {
TranslateAnimation ta = new TranslateAnimation(0, 0, offset, offset);
ta.setDuration(0);
ta.setFillAfter(true);
view.setAnimation(ta);
ta.start();
}
private TranslateAnimation getTranslateAnimator(float targetX, float targetY) {
TranslateAnimation translateAnimation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0f,
Animation.ABSOLUTE, targetX,
Animation.RELATIVE_TO_SELF, 0f,
Animation.ABSOLUTE, targetY);
// RecyclerView默认移动动画250ms 这里设置360ms 是为了防止在位移动画结束后 remove(view)过早 导致闪烁
translateAnimation.setDuration(360);
translateAnimation.setFillAfter(true);
return translateAnimation;
}
/**
* 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);
}
public static void viticalIn(View view, long durationMillis, long delayMillis) {
TranslateAnimation animation = new TranslateAnimation(rela2, 0, rela2, 0, rela2, 1, rela2, 0);
animation.setFillAfter(true);
baseIn(view, animation, durationMillis, delayMillis);
}
private TranslateAnimation getTranslateAnimator(float targetX, float targetY) {
TranslateAnimation translateAnimation = new TranslateAnimation(1, 0.0f, 0, targetX, 1, 0.0f, 0, targetY);
translateAnimation.setDuration(ANIM_TIME);
translateAnimation.setFillAfter(true);
return translateAnimation;
}
private void initAnimations() {
mTurnupAnimation = new RotateAnimation(0, -180,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
mTurnupAnimation.setInterpolator(new LinearInterpolator());
mTurnupAnimation.setDuration(500);
mTurnupAnimation.setFillAfter(true);
mTurndownAnimation = new RotateAnimation(-180, 0,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
mTurndownAnimation.setInterpolator(new LinearInterpolator());
mTurndownAnimation.setDuration(500);
mTurndownAnimation.setFillAfter(true);
mTranslateAnimationOne = new TranslateAnimation(0, 100, 0, 100);
mTranslateAnimationOne
.setInterpolator(new AccelerateDecelerateInterpolator());
mTranslateAnimationOne.setDuration(1000);
mTranslateAnimationOne.setFillAfter(true);
mTranslateAnimationTwo = new TranslateAnimation(100, 100, 0, 100);
mTranslateAnimationTwo
.setInterpolator(new AccelerateDecelerateInterpolator());
mTranslateAnimationTwo.setDuration(1000);
mTranslateAnimationTwo.setFillAfter(true);
mAlphaAnimationOne = new AlphaAnimation(1, 0);
mAlphaAnimationOne.setDuration(500);
mAlphaAnimationOne.setFillAfter(true);
mAlphaAnimationTwo = new AlphaAnimation(0, 1);
mAlphaAnimationTwo.setDuration(1000);
mAlphaAnimationTwo.setStartOffset(500);
mAlphaAnimationTwo.setFillAfter(true);
mAlphaAnimationSet = new AnimationSet(false);
mAlphaAnimationSet.addAnimation(mAlphaAnimationOne);
mAlphaAnimationSet.addAnimation(mAlphaAnimationTwo);
mAlphaAnimationSet.setDuration(5000);
mAlphaAnimationSet.setFillAfter(true);
mScaleAnimation = new ScaleAnimation(1, 1.5f, 1, 1.5f);
mScaleAnimation.setDuration(1000);
mScaleAnimation.setFillAfter(true);
}