点击开始按钮时,SeekBar
动画开始。
点击暂停按钮后,SeekBar
动画将在android中暂停。
我测试了ValueAnimator
,但是暂停和取消均无效。
private static final String PLAY = "play";
private static final String PAUSE = "pause";
private static final String TAG = "seekBar animation";
private String playMode = PAUSE;
private boolean firstPlay = true;
ValueAnimator anim = ValueAnimator.ofInt(0, 100);
anim.setDuration(40000);
anim.addUpdateListener(animation -> {
int animProgress = (Integer) animation.getAnimatedValue();
seekBar.setProgress(animProgress);
});
点击了播放按钮
PlayMusicBtn.setOnClickListener(v -> {
if (playMode.equals(PLAY)) {
playMode = PAUSE;
anim.pause();
Log.i(TAG, "anim must pause");
} else if (playMode.equals(PAUSE)) {
playMode = PLAY;
if (firstPlay) {
anim.start();
} else {
anim.resume();
Log.i(TAG, "animation: resume");
}
firstPlay = false;
}
});