微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

仅从 AnimatorVectorDrawable 动画一个目标

如何解决仅从 AnimatorVectorDrawable 动画一个目标

例如,我只想在特定条件下选择一个目标。怎么可能?提前致谢。

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

解决方法

我想在特定条件下只选择一个目标

不可能只有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?
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。