I've got a TextView that I would like to count down (3...2...1...stuff happens).
To make it a little more interesting, I want each digit to start at full opacity, and fade out to transparency.
Is there a simple way of doing this?
I've got a TextView that I would like to count down (3...2...1...stuff happens).
To make it a little more interesting, I want each digit to start at full opacity, and fade out to transparency.
Is there a simple way of doing this?
Try something like this:
I just typed it out, so it might not compile as is.
Take a look at
CountDownAnimation
.I first tried @dmon solution, but since every animation starts at the end of the previous one you end up having a delay after several calls.
So, I implemented
CountDownAnimation
class which uses aHandler
and thepostDelayed
function. By default, it uses the alpha animation, but you can set any animation. You can download the project here.I've used a more conventional Android-style animation for this:
You can play with the
0
andcount
values to make the counter go from any number to any number, and play with the1000
to set the duration of the entire animation.Note that this supports Android API level 11 and above, but you can use the awesome nineoldandroids project to make it backward compatible easily.