【问题标题】: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?
    }
    
    

    【讨论】:

      猜你喜欢
      • 2020-03-24
      • 2011-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-03
      • 1970-01-01
      • 1970-01-01
      • 2013-07-22
      相关资源
      最近更新 更多