Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Count animation up to down when using CountDownTimer class

I want my countdown text animate up to down when counting like GIF file attached bellow. currently it animate like normal fade. I use CountDownTimer class to count and a TextView for timer. Here is code below:

//somecode
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    CountText=(TextView)findViewById(R.id.countText);
    CounterClass timer = new CounterClass(15000,1000);
    timer.start();
}

CounterClass.java

 public class CounterClass extends CountDownTimer {

     public CounterClass(long millisInFuture, long countDownInterval) {
         super(millisInFuture, countDownInterval);
     }

     @Override
     public void onTick(long millisUntilFinished) {
         millis = millisUntilFinished;
         String hms = String.format("%02d:%02d",
                    TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)),
                    TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)));
         System.out.println(hms);

         CountText.setText(hms);
      }

      @Override
      public void onFinish() {

      }

   }

Is there any way i can achieve this? Been trying to get past 2 days. I know there is solution by creating 4 different text and animate but i cant use it because of some reason. so Any help would be appreciated. Thanks!

enter image description here

like image 313
Fajar Khan Avatar asked Aug 04 '26 08:08

Fajar Khan


1 Answers

If anyone still looking for answer to this.

Try this Library

You can get the desired animation using this.

like image 114
Fajar Khan Avatar answered Aug 06 '26 01:08

Fajar Khan