我有一个计时器,可以运行一段时间。在这段时间里,我想为我拥有的两个imageview触发一个动画。假设计时器设置为8分钟,我希望在前1分钟内触发动画,然后在接下来的2分钟内停止并触发下一个动画,依此类推。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
stepupimage = (ImageView)findViewById(R.id.stepup);
stepdownimage = (ImageView)findViewById(R.id.stepdown);
Animation animation = AnimationUtils.loadAnimation(MainActivity2.this, R.anim.fade_in);
这是计时器的方法,我调用了启动倒计时的按钮:
private void startTimer()
{
mCountDownTimer = new CountDownTimer(mTimeLeftInMillis, 1000) {
@Override
public void onTick(long millisUntilFinished) {
mTimeLeftInMillis = millisUntilFinished;
updateCountDownText();
progress++;
pb.setProgress((int)progress*100/(480000/1000));
}
@Override
public void onFinish()
{
progress++;
pb.setProgress(100);
//Vibration
if (Build.VERSION.SDK_INT >= 26)
{
((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(VibrationEffect.createOneShot(150, VibrationEffect.DEFAULT_AMPLITUDE));
Toast.makeText(MainActivity2.this,"Done",Toast.LENGTH_SHORT).show();
}
else
{
((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(VibrationEffect.createWaveform(new long[]{150}, new int[]{VibrationEffect.EFFECT_CLICK},-1));
}
}
}.start();
}
那我该怎么办?我要补充什么?
暂无答案!
目前还没有任何答案,快来回答吧!