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

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

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

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

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

Android中使用SVG
VectorDrawable 创建基于XML的静态的SVG图形,
Android 5.X SVG矢量动画机制——Android群英传_第1张图片

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

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代码:

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();

你可能感兴趣的:(学习笔记)