今天想学习android中的动画,刚开始学碰见一个头疼的问题,自定义动画中往往会根据插值器interpolatedTime计算三角函数,所以现在回顾一下:
正弦型函数解析式:y=Asin(ωx+φ)+b
φ:决定波形与X轴位置关系或横向移动距离(左加右减)
ω:决定周期(T=2π/∣ω∣)
A:决定峰值(即纵向拉伸压缩的倍数)
b:表示波形在Y轴的位置关系或纵向移动距离(上加下减)
举个例子来说吧
public class CustomAnimation extends Animation {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
t.getMatrix().setTranslate(
(float) Math.sin(interpolatedTime * 10) * 5,
(float) Math.sin(interpolatedTime * 10) * 5
);//这里10代表<span style="color: rgb(51, 51, 51); font-family: arial, 宋体, sans-serif; font-size: 14px; line-height: 24px; text-indent: 28px;">ω,也就是决定周期,走过2<span style="color: rgb(51, 51, 51); font-family: arial, 宋体, sans-serif; font-size: 14px; line-height: 24px; text-indent: 28px;">π的时间越短(频率快慢),5代表<span style="color: rgb(51, 51, 51); font-family: arial, 宋体, sans-serif; font-size: 14px; line-height: 24px; text-indent: 28px;">A,也就是代表振幅(大小)</span></span></span>
super.applyTransformation(interpolatedTime, t);
}
}