【发布时间】:2015-08-18 21:34:43
【问题描述】:
我正在尝试使用 ObjectAnimator 制作搜索栏动画。问题是如果我将 ObjectiAnimator 的持续时间设置为较大的值,它会在开始之前有延迟。这是我的代码:
_replayBar.setMax(FlightLogger.getTimeLength());
_replayBar.setOnSeekBarChangeListener(this);
_timeMax.setText(secondsToTimeFormat(0) + "/" + secondsToTimeFormat(_replayBar.getMax()));
anim=ObjectAnimator.ofInt(_replayBar, "progress", 0, _replayBar.getMax());
anim.setDuration(_replayBar.getMax() * 1000);
其中 anim 是 objectAnimator,_replaybar 是 seekbar,FlightLogger.getTimeLenth() 以毫秒为单位返回时间。
我要做的只是让搜索栏实时更新过程以秒为单位。但是如果传递给 anim.setDuration 的值变得太大(即:2分钟),它将延迟启动几秒钟。如果持续时间更长(即:1 小时),延迟可能是几分钟。
我也尝试使用 ValueAnimator,代码类似,加上 onAnimationUpdate 监听器如下:
anim.addUpdateListener(new ObjectAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
if (!anim.isRunning())
anim.resume();
animProgress = (Integer) valueAnimator.getAnimatedValue();
Log.d(TAG, "progress: " + valueAnimator.getAnimatedValue());
_replayBar.setProgress(animProgress);
}
});
我在侦听器中记录进程,并为每个进程返回重复值,类似于ValueAnimator duplicate Values when starting。
谁能帮我解决这个问题? 非常感谢
【问题讨论】:
-
您希望多久更改一次“progress”属性?
-
每秒,类似于播放视频
-
所以使用
android.os.CountDownTimer或原始Handler,动画师不适合这种用例 -
我试试吧。感谢您的帮助