简体   繁体   English

Java与BigInteger一起使用ValueAnimator吗?

[英]Java using ValueAnimator with BigInteger?

I'm trying to animate between two values using BigInteger instead of int like I was using before. 我正在尝试使用BigInteger在两个值之间建立动画,而不是像以前那样使用int进行动画处理。 So far I have not found a way to do this, is it possible? 到目前为止,我还没有找到一种方法可以执行此操作吗?

final ValueAnimator amountAnimation = ValueAnimator.ofInt(initialValue, finalValue);

Of course, BigInteger is not accepted there... Thank you 当然,那里不接受BigInteger ...谢谢

You can use any type in ValueAnimator, as long as You provide your own TypeEvaluator (somehow pseudocode example): 您可以在ValueAnimator中使用任何类型,只要您提供自己的TypeEvaluator (某种程度上是伪代码示例):

public class BigIntegerEvaluator implements TypeEvaluator<BigInteger>{
    @Override
    public BigInteger evaluate(float v, BigInteger start, BigInteger end) {
        //todo: implement this
        return start + v * (end - start);
    }
}

Then provide it into general valueAnimator: 然后将其提供给常规valueAnimator:

final ValueAnimator amountAnimation = ValueAnimator.ofObject(new BigIntegerEvaluator(), initialValue, finalValue);

But I'm not sure about animating on type BigInteger itself since Evaluator is called on each frame with new fraction, are you sure long type is not enough for your use case? 但是我不确定是否要对BigInteger类型进行动画处理,因为在每个框架上都用新分数调用了Evaluator,您确定long型不足以使用您的用例吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM