Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Simple TextView Animation

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?

like image 921
Rob Avatar asked Jan 31 '12 02:01

Rob


1 Answers

Try something like this:

 private void countDown(final TextView tv, final int count) {
   if (count == 0) { 
     tv.setText(""); //Note: the TextView will be visible again here.
     return;
   } 
   tv.setText(String.valueOf(count));
   AlphaAnimation animation = new AlphaAnimation(1.0f, 0.0f);
   animation.setDuration(1000);
   animation.setAnimationListener(new AnimationListener() {
     public void onAnimationEnd(Animation anim) {
       countDown(tv, count - 1);
     }
     ... //implement the other two methods
   });
   tv.startAnimation(animation);
 }

I just typed it out, so it might not compile as is.

like image 122
dmon Avatar answered Sep 27 '22 17:09

dmon