0

这是我的代码:

 public static void countTextViewTravelMode(final Integer value, final TextView myView, final CrudStateCallback back){
    Integer begin = 0;
    try {
        begin = Integer.parseInt(myView.getText().toString());
    }catch (Exception e){
        Log.e("","error trying to get value travel:" + e.getMessage());
    }
    ValueAnimator animator = ValueAnimator.ofInt(begin, value);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        public void onAnimationUpdate(ValueAnimator animation) {
            String string = animation.getAnimatedValue() + "";
            myView.setText(string);
        }
    });
    animator.setEvaluator(new TypeEvaluator<Integer>() {
        public Integer evaluate(float fraction, Integer startValue, Integer endValue) {
            return Math.round((endValue - startValue) * fraction);
        }
    });
    animator.setDuration(1000);
    animator.start();
    if(back!= null)
        back.onResponse("");
}

这在调用活动时调用一次,在完成获取新数据的 Api 调用后调用一次。第一次它从 0 变为正确的值。第二次,它回到 0,从 0 开始,总是停在一个小于想要的数字的随机数上。我怎样才能让它不从 0 重新启动,并且在想要的 nr 处完成?

4

1 回答 1

1

这是错误的:

  animator.setEvaluator(new TypeEvaluator<Integer>() {
    public Integer evaluate(float fraction, Integer startValue, Integer endValue) {
        return Math.round((endValue - startValue) * fraction);
    } 
}); 

把它拿出来,它就像一个魅力

于 2016-04-29T10:26:26.720 回答