在指定的时间内,通过get和set方法不断修改view的属性达到的动画效果
ViewPropertyAnimator
view.animate()
.translationX(200.dp)
.translationY(100.dp)
.alpha(0.5f)
.scaleX(2f)
.scaleY(2f)
.rotation(90f)
.setStartDelay(1000)
ObjectAnimator
//需要在radius的set方法调用 invalidate()
val animator = ObjectAnimator.ofFloat(view, "radius", 150.dp)
animator.startDelay = 1000
animator.duration = 1000
animator.start()
AnimatorSet
val bottomFlipAnimator = ObjectAnimator.ofFloat(view, "bottomFlip", 60f)
bottomFlipAnimator.startDelay = 1000
bottomFlipAnimator.duration = 1000
val flipRotationAnimator = ObjectAnimator.ofFloat(view, "flipRotation", 270f)
flipRotationAnimator.startDelay = 200
flipRotationAnimator.duration = 1000
val topFlipAnimator = ObjectAnimator.ofFloat(view, "topFlip", - 60f)
topFlipAnimator.startDelay = 200
topFlipAnimator.duration = 1000
val animatorSet = AnimatorSet()
animatorSet.playSequentially(bottomFlipAnimator, flipRotationAnimator, topFlipAnimator)
animatorSet.start()
PropertyValuesHolder
val bottomFlipHolder = PropertyValuesHolder.ofFloat("bottomFlip", 60f)
val flipRotationHolder = PropertyValuesHolder.ofFloat("flipRotation", 270f)
val topFlipHolder = PropertyValuesHolder.ofFloat("topFlip", - 60f)
val holderAnimator = ObjectAnimator.ofPropertyValuesHolder(view, bottomFlipHolder, flipRotationHolder, topFlipHolder)
holderAnimator.startDelay = 1000
holderAnimator.duration = 2000
holderAnimator.start()
Keyframe
val length = 200.dp
val keyframe1 = Keyframe.ofFloat(0f, 0f)
val keyframe2 = Keyframe.ofFloat(0.2f, 1.5f * length)
val keyframe3 = Keyframe.ofFloat(0.8f, 0.6f * length)
val keyframe4 = Keyframe.ofFloat(1f, 1f * length)
val keyframeHolder = PropertyValuesHolder.ofKeyframe("translationX", keyframe1, keyframe2, keyframe3, keyframe4)
val animator = ObjectAnimator.ofPropertyValuesHolder(view, keyframeHolder)
animator.startDelay = 1000
animator.duration = 2000
animator.start()
TypeEvaluator
val animator = ObjectAnimator.ofObject(view, "point", PointFEvaluator(), PointF(100.dp, 200.dp))
animator.startDelay = 1000
animator.duration = 2000
animator.start()
class PointFEvaluator : TypeEvaluator<PointF> {
override fun evaluate(fraction: Float, startValue: PointF, endValue: PointF): PointF {
val startX = startValue.x
val endX = endValue.x
val currentX = startX + (endX - startX) * fraction
val startY = startValue.y
val endY = endValue.y
val currentY = startY + (endY - startY) * fraction
return PointF(currentX, currentY)
}
}