Animate only ONE target from AnimatorVectorDrawable

99 Views Asked by At

I want to select only one target on specific conditions for example. How it is possible? Thanks in advance.

<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/ic_worldreloaded">

<target
    android:name="alles"
    android:animation="@animator/alles" />

    <target
        android:name="alles2"
        android:animation="@animator/alles2" />

</animated-vector>
1

There are 1 best solutions below

0
On

I want to select only one target on specific conditions

It is impossible only xml. You can make a two animated vector resource files below


alles.xml

<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/ic_worldreloaded">

    <target
        android:name="alles"
        android:animation="@animator/alles" />

</animated-vector>

alles2.xml

<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/ic_worldreloaded">

    <target
        android:name="alles2"
        android:animation="@animator/alles2" />

</animated-vector>

finally, on the code behind

val animatedVector 
= if(condition that you want) {
    ContextCompat.getDrawable(this, R.drawable.alles) as AnimatedVectorDrawable? 
} else {
    ContextCompat.getDrawable(this, R.drawable.alles2) as AnimatedVectorDrawable?
}