首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >仅为AnimatorVectorDrawable中的一个目标设置动画

仅为AnimatorVectorDrawable中的一个目标设置动画
EN

Stack Overflow用户
提问于 2021-02-28 14:21:11
回答 1查看 28关注 0票数 0

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

代码语言:javascript
运行
复制
<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>
EN

回答 1

Stack Overflow用户

发布于 2021-02-28 23:32:51

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

只有xml是不可能的。你可以在下面创建一个two animated vector resource files

alles.xml

代码语言:javascript
运行
复制
<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

代码语言:javascript
运行
复制
<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>

最后,关于后面的代码

代码语言:javascript
运行
复制
val animatedVector 
= if(condition that you want) {
    ContextCompat.getDrawable(this, R.drawable.alles) as AnimatedVectorDrawable? 
} else {
    ContextCompat.getDrawable(this, R.drawable.alles2) as AnimatedVectorDrawable?
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66406384

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档