【Android】仿蚂蚁森林,树木弹动动画

 

先看效果图:

【Android】仿蚂蚁森林,树木弹动动画_第1张图片

重点是插值器,我之前一直没想到会做出来。全靠群里的丁大佬。。。

public class TreeAnimation {

    public static Animation getAnimation() {
        // 创建缩放的动画对象
        ScaleAnimation sa = new ScaleAnimation(1f, 1.0f, 1.0f, 1.1f, ScaleAnimation.RELATIVE_TO_SELF, 0.0f, ScaleAnimation.RELATIVE_TO_SELF, 1.0f);
        // 设置动画播放的时间
        sa.setDuration(1500);
        sa.setInterpolator(new SpringInterpolator(0.3f));
        return sa;
    }

}

插值器代码:

public class SpringInterpolator implements Interpolator {

    //控制弹簧系数
    private float factor;

    public SpringInterpolator(float factor) {
        this.factor = factor;
    }

    @Override
    public float getInterpolation(float input) {
        //factor = 0.4
//        pow(2, -10 * x) * sin((x - factor / 4) * (2 * PI) / factor) + 1

        return (float) -(Math.pow(2, -10 * input) * Math.sin((input - factor / 4) * (2 * Math.PI) / factor) );
    }
}

 

你可能感兴趣的:(Android,动画,支付宝)