SVG动画demo

第一步:创建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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值