我想将移动手的方法runSecrunMin组合为一种方法。这些方法将分针和秒针移到表盘上。帮助,谢谢。

public void settTime(int seconds) {
  if(isTimer)
   return;
    tTime = seconds;
     int minutes = seconds / 60;
     int hours = minutes / 60;
     minutes = minutes % 60;
     seconds = seconds % 60;
     tTimeLabel.setText(String.format("%02d:%02d:%02d", hours, minutes, seconds));
      runSec(seconds);
      runMin(minutes);
}

public void runSec(int seconds) {
 RotateAnimation rotateAnimation = new RotateAnimation(seconds * 6, seconds * 6,
 Animation.RELATIVE_TO_SELF, 0.5f,Animation.RELATIVE_TO_SELF, 0.5f);
 rotateAnimation.setFillAfter(true);
 csecond.startAnimation(rotateAnimation);
}

public void runMin(int minutes) {
 RotateAnimation rotateAnimation = new RotateAnimation(minutes * 6, minutes * 6,
 Animation.RELATIVE_TO_SELF, 0.5f,Animation.RELATIVE_TO_SELF, 0.5f);
 rotateAnimation.setFillAfter(true);
cminute.startAnimation(rotateAnimation);
}

最佳答案

public void runMin(int minutes) {
   cminute.startAnimation(createAnimation(minutes*6));
}

public void runSec(int seconds) {
  csecond.startAnimation(createAnimation(seconds*6));
}

public RotateAnimation createAnimation(int time) {
   RotateAnimation rotateAnimation = new RotateAnimation(time, time,
   Animation.RELATIVE_TO_SELF, 0.5f,Animation.RELATIVE_TO_SELF, 0.5f);
   rotateAnimation.setFillAfter(true);
   return rotateAnimation;
}

10-08 00:50