2016-11-02 1 views

Répondre

0

Vous pouvez ajouter un écouteur au TranslateAnimation et lorsque c'est fait, changez la position du View en position finale de l'animation.

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); 
} 
}); 

Mais je vous suggère de passer en fait de l'ancien TranslateAnimation/ScaleAnimation type de cours, au nouveau cadre ViewPropertyAnimator (http://android-developers.blogspot.co.il/2011/05/introducing-viewpropertyanimator.html). Dans le nouveau cadre, vous ne devez pas changer de position comme dans le code ci-dessus, et la syntaxe est beaucoup plus simple:

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

vous pouvez également utiliser AnimatorSet pour créer un ensemble d'animation à jouer ensemble ou un après l'autre.

Pour en savoir plus: https://developer.android.com/reference/android/view/ViewPropertyAnimator.html

+0

Oui ça marche! Je n'ai pas du tout pensé à l'auditeur – Kemix