2010-09-16 40 views
6

我在xml文件中創建了一個動畫。 我把它在一個TextView這樣的:使用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 

這將運行一次,即使我設置了重複計數。 有什麼想法?

+0

我發現了另一個答案的解決方案的兩倍。適用於我。乾杯! https://stackoverflow.com/a/4844448/6049708 – 2017-05-29 09:35:43

回答

2

這很奇怪,我有同樣的問題,然後我發現了關於setRepeatCount和setRepeatMode函數,並實現它們,然後他們爲我工作得很好。

這裏是我的代碼:

new AnimationUtils(); 

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

也許嘗試扭轉你的setRepeatCountsetRepeatMode功能的順序?你的觀點可能有些奇怪嗎?

+0

更改順序或用「-1,2」代替常量確實爲我解決了這個問題。我以編程方式將Android的動畫添加到ImageView和TextView,從Android 3.2到4.x。 – 2012-11-27 06:46:41

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

你有你的動畫,例如我做了以下(眨眼識別動畫)

<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>