在Android开发中,可以使用VectorDrawable和AnimatedVectorDrawable类来实现矢量图形和矢量动画。
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF0000"
android:pathData="M12,2C6.48,2,2,6.48,2,12s4.48,10,10,10s10-4.48,10-10S17.52,2,12,2z"/>
</vector>
vector_drawable.xml:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:name="path"
android:fillColor="#FF0000"
android:pathData="M12,2C6.48,2,2,6.48,2,12s4.48,10,10,10s10-4.48,10-10S17.52,2,12,2z"/>
</vector>
animated_vector_drawable.xml:
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/vector_drawable">
<target
android:name="path"
android:animation="@anim/path_animation"/>
</animated-vector>
path_animation.xml:
<objectAnimator
android:duration="1000"
android:propertyName="pathData"
android:valueFrom="M12,2C6.48,2,2,6.48,2,12s4.48,10,10,10s10-4.48,10-10S17.52,2,12,2z"
android:valueTo="M12,10C6.48,2,2,6.48,2,12s4.48,10,10,10s10-4.48,10-10S17.52,2,12,10z"/>
以上示例中,animated_vector_drawable.xml中定义了一个AnimatedVectorDrawable,并指定了动画过渡的目标路径和对应的属性动画。通过在代码中加载这个AnimatedVectorDrawable并播放动画,就可以实现矢量图形的动态变化效果。