2010-09-16 4 views
6

J'ai créé une animation dans un fichier xml. Je l'applique sur un textview comme celui-ci:En boucle avec un fichier d'animation XML?

Animation anim = AnimationUtils.loadAnimation(this, R.anim.exit_about); 
anim.setRepeatMode(Animation.RESTART); 
anim.setRepeatCount(Animation.INFINITE); 
v.findViewById(R.id.global_about).startAnimation(anim); // v is my view 

Cela va une fois, même si je mets un nombre de répétitions. Une idée?

+0

J'ai trouvé la solution dans une autre réponse. Travaille pour moi. À votre santé! https://stackoverflow.com/a/4844448/6049708 –

Répondre

2

Ceci est étrange, j'ai eu le même problème, et puis j'ai découvert les fonctions setRepeatCount et setRepeatMode, et les a implémentés, et puis ils ont fonctionné pour moi bien.

voici mon code:

new AnimationUtils(); 

Animation controller = AnimationUtils.loadAnimation(context, R.anim.flasher); 
controller.setRepeatCount(-1); 
controller.setRepeatMode(2); 
sectionText.startAnimation(controller); 

Peut-être essayer d'inverser l'ordre de vos setRepeatCount et setRepeatMode fonctions? Peut-être qu'il se passe quelque chose de bizarre à votre avis?

+0

La modification de l'ordre et le remplacement des constantes par "-1, 2" ont résolu le problème pour moi. J'ajoute l'anim à ImageView et TextView par programme d'Android 3.2 à 4.x. –

0
Animation anim = new AlphaAnimation(0.0f, 1.0f); 
    anim.setDuration(50); //You can manage the time 
    anim.setStartOffset(20); 
    anim.setRepeatMode(Animation.REVERSE); 
    anim.setRepeatCount(Animation.INFINITE); 
    Yuor_textview.startAnimation(anim); 
0

Vous devez double animation, comme je l'ai fait ci-dessous (Blink animation)

<set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1500" android:fillAfter="false" android:repeatMode="reverse"> 
     <alpha android:fromAlpha="1.0" android:toAlpha="0.0" /> // From 0 
     <alpha android:fromAlpha="0.0" android:toAlpha="1.0"/> // To 1 
</set> 
Questions connexes