Je voudrais faire deux types d'animation sur une seule vue: un TranslateAnimation et quelques instants plus tard une ScaleAnimation. Le problème est que lorsque la ScaleAnimation commence, les vues retournent à leur état initial (avant TranslateAnimation). Y a-t-il un moyen de faire ce que je veux?Android: Rester en état d'animation plus ancienne lors du démarrage d'une nouvelle animation
0
A
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
Oui ça marche! Je n'ai pas du tout pensé à l'auditeur – Kemix