Android:ValueAnimator始终提供最终价值

Olc*_*taş 2 animation android

我在下面的方法中将我的ValueAnimator配置为两种颜色之间的淡入淡出。但这是行不通的。它总是给出结束颜色值。

Integer colorFrom;
Integer colorTo;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mGoogleApiClient = buildGoogleApiClient();
    activity = getActivity();
    context = activity.getApplicationContext();
    colorFrom = ContextCompat.getColor(context, R.color.donut_finished_color);
    colorTo = ContextCompat.getColor(context, R.color.Red);
}

@Override
public void onResume() {
    super.onResume();
    setColorAnimation();
}

private void setColorAnimation() {
    long passedTime = Calendar.getInstance().getTime().getTime() - currentEarlyDate.getTime();
    colorAnimator = ValueAnimator.ofObject(argbEvaluator, colorFrom, colorTo);
    colorAnimator.setDuration(currentPrayerTimeLength);
    colorAnimator.setInterpolator(null);
    colorAnimator.addUpdateListener(this);
    colorAnimator.start();
    colorAnimator.setCurrentPlayTime(passedTime);
}

@Override
public void onAnimationUpdate(ValueAnimator animation) {
    Integer colorValue = (Integer) colorAnimator.getAnimatedValue();
    Log.e(Constants.LOG_TAG, "Duration : " + colorAnimator.getDuration());
    Log.e(Constants.LOG_TAG, "Current : " + colorAnimator.getCurrentPlayTime());
    Log.e(Constants.LOG_TAG, "Color : " + colorValue);
    remainingTimeProgress.setFinishedStrokeColor(colorValue);
    remainingTimeProgress.setUnfinishedStrokeColor(colorValue);
}
Run Code Online (Sandbox Code Playgroud)

时间值在日志上似乎不错,但动画颜色值跳到了终点

09-02 17:53:22.032    updateLocationNamesList
09-02 17:59:30.104    setColorAnimation - Length : 10620000
09-02 17:59:30.104    setColorAnimation - Passed : 4290093
09-02 17:53:22.099    onAnimationUpdate - Duration : 10620000
09-02 17:53:22.099    onAnimationUpdate - Current : 0
09-02 17:53:22.099    onAnimationUpdate - Color : -16058881
09-02 17:53:22.100    onAnimationUpdate - Duration : 10620000
09-02 17:53:22.100    onAnimationUpdate - Current : 0
09-02 17:53:22.100    onAnimationUpdate - Color : -10183775
09-02 17:53:22.102    onAnimationUpdate - Duration : 10620000
09-02 17:53:22.102    onAnimationUpdate - Current : 2
09-02 17:53:22.102    onAnimationUpdate - Color : -65536 //Quickly jumps to end
Run Code Online (Sandbox Code Playgroud)

不知道出什么问题了吗?

psk*_*ink 5

请确保你在你的设备启用动画"developer options",如果禁用你的动画简单地从跳跃"start""end"价值