【问题标题】:Apply animation set to shape drawable将动画集应用到可绘制形状
【发布时间】:2016-10-11 09:03:57
【问题描述】:

我有以下可绘制的 red_dot.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
    <solid android:color="#f00" />
    <size
        android:width="30dp"
        android:height="30dp"/>
</shape>

还有动画pulse.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha
        android:fromAlpha="1.0"
        android:toAlpha="0.0"
        android:duration="1000"
        android:repeatMode="reverse"
        android:repeatCount="infinite" />
</set>

如何将动画应用到 XML 文件中的可绘制对象,例如red_dot_animated?如果 red_dot.xml 是矢量文件,则以下是可能的(但不是,因为我们有一个形状)

<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
   android:drawable="@drawable/red_dot_vector" >
     <target
         android:name="circle"
         android:animation="@anim/pulse" />
</animated-vector>

【问题讨论】:

    标签: android android-drawable android-vectordrawable android-shapedrawable


    【解决方案1】:

    您可以做的是创建一个简单的View 并将red_dot 设置为背景并将animation 应用于该view

    <View
      android:layout_width="30dp"
      android:layout_height="30dp"
      android:background="@drawable/red_dot"
      android:id="@+id/anime_view"
    />
    
    View animeView = findViewById(R.id.anime_view);//Apply animation to animeView
    

    【讨论】:

    • 把它放在一个可绘制的 XML 中将具有直接用于 TextView 的 drawableLeft 等的优势。
    猜你喜欢
    • 2021-09-19
    • 1970-01-01
    • 2014-04-13
    • 1970-01-01
    • 1970-01-01
    • 2014-12-07
    • 1970-01-01
    • 1970-01-01
    • 2013-10-02
    相关资源
    最近更新 更多