Android 5.X SVG矢量动画机制——Android群英传

SVG : Scalable Vector Graphics 可伸缩矢量图形
与Bitmap比较:Bitmap通过在每个像素点上存储色彩信息来表达图像,而SVG是个绘图标准,最大的优点就是放大不会失真,不需像Bitmap需要为不同分辨率设计多套图标。

<path>标签 就像用指令的方式来控制一只画笔

常用指令:
L:绘制直线
M:移动
A:绘制弧线

SVG编辑器 编辑SVG图形 http://editor.method.ac/

Android中使用SVG
VectorDrawable 创建基于XML的静态的SVG图形,
这里写图片描述

<vector .....
    <group ......>
             <path..../>
      `</group>`       ./>

AnimatrdVectorDrawable 给VectorDrawable提供动画效果

<aniamted-vetor                                               xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/vector">
<target
    android:name="test"
    android:animation="@anim/anim_path1"/>
</animated-vector>
对应的vector即为静态的VectorDrawable
<vector   xmlns:android="http://schemas.android.com/apk/res/android"
android:height="200dp"
android:width="200dp"
android:viewporHeight="100"
android:viewporWidth="100">
  <group
     android:name="test"
     android:rotation="0">
     <path          android:strokeColor="@android:color/holo_blue_light"
      android:strokeWidth="2"
      android:pathData="
         M 25 50
         a 25,25 0 1,0 50,0"/>
   </group>
</vector>                           

AnimatedVectorDrwable中指定的target的name属性,必须和VectorDrawable中需要作用的name属性保持一致。target的animatoion属性,将一个动画作用到了对应的name的元素上,objectAnimator代码:

<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
   android:duration="4000"
   android:propertyName="rotation"
   android:valueFrom="0"
   android:valueTo="360"/>

设置给ImageView

<ImageView
       android:id="@+id/image"
       android:layout_gravity="center"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:src="@drawable/anim_vector"/>

代码中:
((Animatable)imageView.getDeawable()).start();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值