美文网首页
估值器 Evaluator

估值器 Evaluator

作者: qpan | 来源:发表于2018-05-16 08:42 被阅读3次
    • 内容
      接口 TypeEvaluator <T>
      常见估值器
      自定义估值器

    • 接口 TypeEvaluator <T>
      本质是:根据比例 计算具体值
      This function returns the result of linearly interpolating the start and end values, with fraction representing the proportion between the start and end values.

    /**
     * Interface for use with the {@link ValueAnimator#setEvaluator(TypeEvaluator)} function. Evaluators
     * allow developers to create animations on arbitrary property types, by allowing them to supply
     * custom evaluators for types that are not automatically understood and used by the animation
     * system.
     *
     * @see ValueAnimator#setEvaluator(TypeEvaluator)
     */
    public interface TypeEvaluator<T> {
    
        /**
         * This function returns the result of linearly interpolating the start and end values, with
         * <code>fraction</code> representing the proportion between the start and end values. The
         * calculation is a simple parametric calculation: <code>result = x0 + t * (x1 - x0)</code>,
         * where <code>x0</code> is <code>startValue</code>, <code>x1</code> is <code>endValue</code>,
         * and <code>t</code> is <code>fraction</code>.
         *
         * @param fraction   The fraction from the starting to the ending values
         * @param startValue The start value.
         * @param endValue   The end value.
         * @return A linear interpolation between the start and end values, given the
         *         <code>fraction</code> parameter.
         */
        public T evaluate(float fraction, T startValue, T endValue);
    
    }
    
    • 常用估值器
    /**
     * This evaluator can be used to perform type interpolation between <code>int</code> values.
     */
    public class IntEvaluator implements TypeEvaluator<Integer> {
    
        /**
         * This function returns the result of linearly interpolating the start and end values, with
         * <code>fraction</code> representing the proportion between the start and end values. The
         * calculation is a simple parametric calculation: <code>result = x0 + t * (v1 - v0)</code>,
         * where <code>x0</code> is <code>startValue</code>, <code>x1</code> is <code>endValue</code>,
         * and <code>t</code> is <code>fraction</code>.
         *
         * @param fraction   The fraction from the starting to the ending values
         * @param startValue The start value; should be of type <code>int</code> or
         *                   <code>Integer</code>
         * @param endValue   The end value; should be of type <code>int</code> or <code>Integer</code>
         * @return A linear interpolation between the start and end values, given the
         *         <code>fraction</code> parameter.
         */
        public Integer evaluate(float fraction, Integer startValue, Integer endValue) {
            int startInt = startValue;
            return (int)(startInt + fraction * (endValue - startInt));
        }
    }
    
    • 自定义估值器
      重写evaluate即可

    相关文章

      网友评论

          本文标题:估值器 Evaluator

          本文链接:https://www.haomeiwen.com/subject/jqiudftx.html