2016-11-02 44 views

回答

0

您可以将侦听器添加到TranslateAnimation,完成后,将View的位置更改为动画的结束位置。

TranslateAnimation anim = new TranslateAnimation(...); 
anim.setAnimationListener(new AnimationListener() { 
@Override 
public void onAnimationStart(Animation animation) { } 
@Override 
public void onAnimationRepeat(Animation animation) { } 
@Override 
public void onAnimationEnd(Animation animation) { 
    view.setX(NEW_X_POSITION); 
    view.setY(NEW_Y_POSITION); 
} 
}); 

但是我建议从旧TranslateAnimation/ScaleAnimation类型的类实际上切换到新ViewPropertyAnimator框架(http://android-developers.blogspot.co.il/2011/05/introducing-viewpropertyanimator.html)。 在新的框架,你没有改变一样在上面的代码位置,而且语法简单得多:

myView.animate().x(500).y(500); 

你也可以用AnimatorSet创建一组动画要一起玩或一个之后。

延伸阅读:https://developer.android.com/reference/android/view/ViewPropertyAnimator.html

+0

是的,它的工作原理!我根本没有想到听众 – Kemix