如何使用开始和停止在搜索栏上设置动画?

时间:2019-05-23 07:41:41

标签: java android animation

点击开始按钮时,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;
    }
});

0 个答案:

没有答案