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

先看效果图:

25193c951367521712a5cc253d196ea4.png

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

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) );

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值