2010-09-16 13 views
6

Ich habe eine Animation in einer XML-Datei. Ich wende es auf einem Textview wie folgt aus:Schleifen mit einer XML-Animationsdatei?

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 

Dies läuft einmal, auch wenn ich eine Wiederholungszahl gesetzt. Irgendeine Idee?

+0

Ich fand Lösung in eine andere Antwort. Funktioniert bei mir. Prost! https://stackoverflow.com/a/4844448/6049708 –

Antwort

2

Das ist seltsam, ich hatte das gleiche Problem, und dann habe ich über die Funktionen setRepeatCount und setRepeatMode herausgefunden und implementiert, und dann funktionierten sie für mich gut.

hier ist mein Code:

new AnimationUtils(); 

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

versuchen Vielleicht die Reihenfolge Ihrer setRepeatCount und setRepeatMode Funktionen Umkehren? Vielleicht gibt es etwas Seltsames mit deiner Sichtweise?

+0

die Reihenfolge ändern noch Konstanten ersetzt durch „-1, 2“ hat es für mich zu lösen. Ich füge die Animation zu ImageView und TextView programmatisch von Android 3.2 zu 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

Sie haben Ihre Animation zu verdoppeln, wie ich weiter unten tat (für 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>