第一步:创建svg对象
<!--设置宽高属性 和网状属性-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="200dp"
android:height="200dp"
android:viewportHeight="100"
android:viewportWidth="100"
>
<!--最基本单位为path,容器为group,group中可以包含多个path和group-->
<!--需要的属性为name ratation为旋转角度-->
<group
android:name="group1"
android:rotation="0">
<!--填充效果为fillColor
边界效果为strokeColor
-->
<path
android:fillColor="@android:color/holo_purple"
android:pathData="M 25 50
a 25,25 0 1,0 50,0"/>
</group>
第二步:创建属性动画
<?xml version="1.0" encoding="utf-8"?>
<!--必须在animator文件夹中定义-->
<!--如果指定属性为pathData,那么需要添加一个属性valueType="pathType"-->
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="5000"
android:propertyName="rotation"
android:valueFrom="0"
android:valueTo="1800"
>
</objectAnimator>
第三步:创建”胶水”将svg和属性动画连接起来
<?xml version="1.0" encoding="utf-8"?>
<!--google工程师将其形容其为胶水,将svg(下面的drawable)和属性动画(target)连接起来-->
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/vector"
>
<!--animation为动画的xml文件
name为需要操纵的属性名称,通过name来确定是修改哪个group中的属性
-->
<target
android:animation="@animator/vector_animator"
android:name="group1"/>
</animated-vector>