【问题标题】:Animate only ONE target from AnimatorVectorDrawable仅对 AnimatedVectorDrawable 中的一个目标进行动画处理
【发布时间】:2021-02-28 06:21:11
【问题描述】:
例如,我只想在特定条件下选择一个目标。怎么可能?提前致谢。
<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>
【问题讨论】:
标签:
android
animation
vector
animatedvectordrawable
【解决方案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?
}