Skip to content

Instantly share code, notes, and snippets.

@riggaroo
Created March 28, 2019 12:56
Show Gist options
  • Save riggaroo/24d0ef28579644c4b127d771b069c241 to your computer and use it in GitHub Desktop.
Save riggaroo/24d0ef28579644c4b127d771b069c241 to your computer and use it in GitHub Desktop.
Example showing how to use PropertyValuesHolder to animate a custom views properties.
private fun animateToPoint(point: Point) {
val propertyX = PropertyValuesHolder.ofFloat(ColorDropperView.PROPERTY_X, dropperPoint.x, point.x)
val propertyY = PropertyValuesHolder.ofFloat(ColorDropperView.PROPERTY_Y, dropperPoint.y, point.y)
val animator = ValueAnimator()
animator.setValues(propertyX, propertyY)
animator.interpolator = OvershootInterpolator()
animator.duration = 100
animator.addUpdateListener { animation ->
val animatedX = animation.getAnimatedValue(ColorDropperView.PROPERTY_X) as Float
val animatedY = animation.getAnimatedValue(ColorDropperView.PROPERTY_Y) as Float
setPoint(Point(animatedX, animatedY))
}
animator.start()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment