AndroidPercentageGadget.java 文件源码

java
阅读 36 收藏 0 点赞 0 评论 0

项目:AndroidPercentageGadget 作者:
private void addAnimation(View v) {
    AnimatorSet set = new AnimatorSet();

    if (v == null) {
        return;
    }

    FloatEvaluator eval = new FloatEvaluator() {
        /**
         * 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>float</code> or
         *                   <code>Float</code>
         * @param endValue   The end value; should be of type <code>float</code> or <code>Float</code>
         * @return A linear interpolation between the start and end values, given the
         * <code>fraction</code> parameter.
         */
        @Override
        public Float evaluate(float fraction, Number startValue, Number endValue) {
            //return super.evaluate(fraction, startValue, endValue);
            double sine = Math.sin(Math.PI * fraction) * 0.2;
            return Float.valueOf((float)(startValue.floatValue() * (1.0 + sine)));
        }
    };

    ObjectAnimator animator1 = ObjectAnimator.ofFloat(v, "scaleX", 1f, 1f);
    animator1.setInterpolator(new LinearInterpolator());
    animator1.setEvaluator(eval);
    animator1.setDuration(250);

    ObjectAnimator animator2 = ObjectAnimator.ofFloat(v, "scaleY", 1f, 1f);
    animator2.setInterpolator(new LinearInterpolator());
    animator2.setEvaluator(eval);
    animator2.setDuration(250);

    set.playTogether(animator1, animator2);
    set.start();
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号