Reputation: 1120
In my Android app, I have a fan image whose rotation speed is set by regulator.
This is the animation part:
private fun setFanSpeed(toggle:Boolean, speed:Float){
var speed:Float = speed
if (!toggle)
speed = 0F
val animation = RotateAnimation(0F, 720F,
Animation.RELATIVE_TO_SELF,0.5f,
Animation.RELATIVE_TO_SELF, 0.5f
)
animation.duration = speedToDuration(speed)*1000
animation.repeatCount = Animation.INFINITE
fan.animation = animation
fan.startAnimation(animation)
}
Unfortunately, the rotating fan feels weird because, instead of rotating at a constant speed i.e 720 rotation in a constant time
it accelerates during the start of the animation, and decelerates to a stop during the end. Then speeds up again for the next rotation.
How can I remove the speed up and the speed down, and just make the animation work at a constant speed?
Upvotes: 0
Views: 55
Reputation: 2651
It seems that AccelerateDecelerateInterpolator is the default interpolator for Animation, against the caption in documentation. Specifying LinearInterpolator explicitly, you'll be able to make it rotate uniformly.
animation.interpolator = LinearInterpolator()
Upvotes: 1