I'm trying to make simple animation that would repeat several times (or infinitely).
It seems that
<?xml version="1.0" encoding="utf-8"?>
Animation firstAnimation = AnimationUtils.loadAnimation(this, R.anim.first_animation);
Update: Back in Sep, 2011 an Android engineer fixed this issue for the most part. The attributes that were ignored in XML now work, with the exception of
fillEnabled which are still ignored (on purpose for some reason). This means it still isn't easy to repeat an
For details please see the overview in the updated docs (explains which attributes are ignored, which work, and which are passed onto children). And for a deeper understanding of what
fillEnabled actually do, see the engineer's (Chet Haase) blog post about it here.
To expand upon answers by Pavel and others: it is true that the
<set> tag is ridiculously buggy. It can't deal correctly with
repeatCount and a number of other attributes.
I spent a few hours figuring out what it can and can't deal with and have submitted a bug report/issue here: Issue 17662
In summary (this concerns
setRepeatCount() / android:repeatCount
This attribute (as well as repeatMode) does not work in code or XML. This makes repeating an entire set of animations difficult.
setDuration() / android:duration
Setting this on an AnimationSet in code WORKS (overrides all durations of children animations), but not when included in the tag in XML
setFillAfter() / android:fillAfter
This works in both code and XML for the tag. Strangely I have gotten it to also work without the need to set fillEnabled to true.
setFillBefore() / android:fillBefore
Seems to have no effect/ignored in both code and XML
setFillEnabled() / android:fillEnabled
Seems to have no effect/ignored in both code and XML. I can still get fillAfter to work even without including fillEnabled or setting fillEnabled to false.
setStartOffset() / android:startOffset
This works only in code and not XML.