Frank
Frank

Reputation: 12298

Android Animated Vector Drawable: change at runtime

Using android.support.design.widget.FloatingActionButton a vector animation (rotate and morph) works perfectly if set from the layout xml, but not from runtime.

Working:

android:src="@drawable/vector_anim_play_to_stop"

Not working:

floatingActionButton.setImageResource(R.drawable.vector_anim_play_to_stop)

it does not animate correctly when set from runtime, it does the rotate animation but not the morph. How is that possible?

in both cases I am starting the animation with:

    Animatable animatable = (Animatable) floatingActionButton.getDrawable();
    animatable.start();

Upvotes: 1

Views: 789

Answers (1)

pskink
pskink

Reputation: 24730

create your Animated Vector Drawable by using static create() method and call setImageDrawable() instead of setImageResource()

Upvotes: 3

Related Questions