Анимировать только ОДНУ цель из AnimatorVectorDrawable

#android #animation #vector #animatedvectordrawable

#Android #Анимация #вектор #animatedvectordrawable

Вопрос:

Например, я хочу выбрать только одну цель для определенных условий. Как это возможно? Заранее спасибо.

 <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:

Я хочу выбрать только одну цель при определенных условиях

Это невозможно только в формате xml. Вы можете сделать two animated vector resource files следующее


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>
 

наконец, о коде, лежащем в основе

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