Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looping with an XML animation file?

Tags:

android

I created an animation in an xml file. I apply it on a textview like this :

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 

This runs once even if I set a repeat count. Any idea ?

like image 417
arnouf Avatar asked Sep 16 '10 12:09

arnouf


People also ask

Where is the animation XML file placed?

XML file saved at res/anim/my_overshoot_interpolator.

What are the two different type of view animation?

These three types of animation fall into two categories: frame animations and tweened animations. Unsurprisingly, frame-base animations are a type of frame animation, whereas View- and Property-based animations are types of tweened animations.


2 Answers

This is odd, I had the same problem, and then I found out about the setRepeatCount and setRepeatMode functions, and implemented them, and then they worked for me fine.

here's my code:

new AnimationUtils();

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

Maybe try reversing the order of your setRepeatCount and setRepeatMode functions? Maybe there is something weird going on with your view?

like image 111
blorgggg Avatar answered Oct 12 '22 00:10

blorgggg


    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);
like image 21
Pooja Avatar answered Oct 11 '22 22:10

Pooja