Reputation: 6187
I know we can draw a vector drawable like this on canvas:
vectorDrawable.setBounds(left, top, right, bottom);
vectorDrawable.draw(canvas);
but Is it possible to use animatedVectorDrawables in custom view?
Upvotes: 3
Views: 864
Reputation: 19446
Yes, it is possible, and looks like the snippet you have would work. Be sure to set bounds and call the start()
method on the drawable to start the animation.
class MyCustomView : View {
lateinit var animVectDrawable: AnimatedVectorDrawable
fun startAnim() {
animVectDrawable.setBounds(left, top, right, bottom)
animVectDrawable.start()
shouldDrawAnim = true
}
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
if (shouldDrawAnim) {
animVectDrawable.draw(canvas)
}
}
}
Upvotes: 2