1. 使用系统自带矢量图动画
1.1 Android 系统自带矢量绘图动画 AnimatedVectorDrawable,官网Api地址
AnimatedVectorDrawable
https://developer.android.google.cn/reference/android/graphics/drawable/AnimatedVectorDrawable
1.2 需要 .svg 格式文件,绘图软件绘制导出,或者下载.svg 文件
1.3 Android studio 导入 .svg 文件,得到矢量图文件,例如 ic_my_vector.xml
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="240"
android:viewportHeight="240">
<path
android:fillColor="#00000000"
android:pathData="M66.28,60.75L170.22,60.75A8.03,8.03 0,0 1,178.25 68.78L178.25,172.22A8.03,8.03 0,0 1,170.22 180.25L66.28,180.25A8.03,8.03 0,0 1,58.25 172.22L58.25,68.78A8.03,8.03 0,0 1,66.28 60.75z"
android:strokeWidth="7"
android:strokeColor="#ed1e79" />
<path
android:fillColor="#00ff00"
android:pathData="M125.41,96l98.4,66.51 -90,52L125.41,96m-3.61,-10.1A3.84,3.84 0,0 0,118 90l9.21,130a3.85,3.85 0,0 0,5.75 3.05l98.76,-57a3.84,3.84 0,0 0,0.23 -6.5l-108,-73a3.78,3.78 0,0 0,-2.14 -0.66Z" />
<path
android:fillColor="#0000ff"
android:pathData="M89,102a50,50 0,1 1,-50 50,50.06 50.06,0 0,1 50,-50m0,-7a57,57 0,1 0,57 57A57,57 0,0 0,89 95Z" />
</vector>
1.4 根据官方文档,创建动画文件 my_animated_vector.xml,供布局文件调用
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt">
<aapt:attr name="android:drawable">
<vector
android:width="24dp"