Android的简单的TextView动画简单、动画、Android、TextView

2023-09-05 07:39:48 作者:12.花开似锦

我有一个,我想倒计时(3 ...... 2 ...... 1 ......事情发生)。

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?

推荐答案

尝试是这样的:

 private void countDown(final TextView tv, final count) {
   if (count == 0) { 
     tv.setText(""); //Note: the TextView will be visible again here.
     return;
   } 
   tv.setText(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.