0

I have a TextView that acts as a warning label when a user tries to do something they shouldn't. I want it to blink a few times before staying there at the end. I have blinking once working fine, but it will not repeat the animation. Is there something wrong with my animation?(because i have read the other questions about android animation and reportedly they work)

private void blink(int count){
    if(count>0) {
        AnimationSet anime = new AnimationSet(true);
        Animation anim = new AlphaAnimation(0.0f, 1.0f);
        anim.setDuration(600);
        Animation ani = new AlphaAnimation(1.0f, 0.0f);
        ani.setDuration(600);
        ani.setStartOffset(2000);
        anime.addAnimation(anim);
        anime.addAnimation(ani);
        //anime.setStartOffset(0);
        //anime.setStartTime(0);
        //anime.setRepeatCount(Animation.INFINITE);
        anime.setRepeatCount(count);
        anime.setRepeatMode(Animation.RESTART);
        anime.setFillAfter(true);
        tWarningText.startAnimation(anime);

    }

}

clearAnimation is called when some buttons are pressed, because tWarningText is, well, a warning text, I want it to stay there until they do something about it.

Jody Sowald
  • 342
  • 3
  • 18
  • 1
    You can use `setRepeatCount(10)` if you want to repeat blink for just 10 times when user goes wrong – Omkar Oct 24 '16 at 15:11

1 Answers1

0

Instead of clearing animation after definite time, you can limit repeat count. This should also work fine.

public void blink(View view, int count) {
    Animation anim = new AlphaAnimation(0.0f, 1.0f);
    anim.setDuration(50);
    anim.setStartOffset(20);
    anim.setRepeatMode(Animation.REVERSE);
    anim.setRepeatCount(count);
    view.startAnimation(anim);
}

Usage: blink(textView, 10);

referred from sany's answer.

Community
  • 1
  • 1
Omkar
  • 1,493
  • 3
  • 17
  • 36
  • using setRepeatCount does not cause it to repeat, just as setting it to repeat infinitely does not cause it to repeat. This is the problem – Jody Sowald Oct 24 '16 at 15:45
  • Try reducing `setStartOffset(20)` and `setDuration(50)` and use single animation instead of animation set. Use exact method I provided and check. – Omkar Oct 24 '16 at 15:55