Android VectorDrawable的理解笔记

Lollipop中有一个非常好的新特性是VectorDrawable以及相关的一些类,他们为我们提供了添加复杂矢量图形的强大功能,同时也提供了动画显示这些图形的方法。矢量图形的好处是放大不会失真,可以适应不同分辨率的屏幕。

<vector xmlns:android="http://schemas.android.com/apk/res/android"

android:height="256dp"

android:width="256dp"

android:viewportWidth="32"

android:viewportHeight="32">

<path android:fillColor="#8fff"

android:pathData="M20.5,9.5 c-1.955,0,-3.83,1.268,-4.5,3 c-0.67,-1.732,-2.547,-3,-4.5,-3 C8.957,9.5,7,11.432,7,14 c0,3.53,3.793,6.257,9,11.5 c5.207,-5.242,9,-7.97,9,-11.5 C25,11.432,23.043,9.5,20.5,9.5z" />

VectorDrawable 包含5个元素

<Vector>

-width,height(可绘画对象的内在尺寸)

-viewportWidth,viewportHeight(虚拟画布的大小)

-Path  

          -name(name属性是为了描述path的用处,但它还可以用在为指定path指定一个动画)

          -fillColor(内容的填充颜色)

          -pathData(绘制内容)

                          -M /m 绝对坐标/相对坐标(move移动到某一点)

                          -L/l 绝对坐标/相对坐标 (line链接到某一点简化命令H(x) 水平连接、V(y)垂直         

                                  连接)

                          -Z/z (close闭合,没有参数,连接起点和终点)

                          -C/c(cubic bezier 三次贝塞尔曲线)

                          -Q/q(quatratic bezier 二次贝塞尔曲线)

                          -A/a (ellipse 圆弧)

                           参数之间用空格或逗号隔开

-group(包裹path使用属性动画来控制translateY等属性)


<animated-vector xmlns:android="http://schemas.android.com/apk/res/android" 

<target android:drawable="@drawable/vectordrawable" >

            android:name="rotationGroup"

            android:animation="@anim/rotation" />

<animated-vector>(定义控制多个group的动画)

-target(根据group的name属性指定group的动画效果)

          -drawable(指定的vector文件名)

          -name(group中的name相对应)

          -animation(动画资源)

          

          

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,823评论 25 709
  • Android Vector曲折的兼容之路 两年前写书的时候,就在研究Android L提出的Vector,可研究...
    eclipse_xu阅读 35,283评论 30 263
  • afinalAfinal是一个android的ioc,orm框架 https://github.com/yangf...
    passiontim阅读 15,724评论 2 45
  • 2017第一天,怀着忐忑不安的心情去了机场。换了登机牌,托运了行了,就在大厅候着。这忐忑不安的心,并不是因为乘坐飞...
    琦静雪阅读 1,456评论 0 0
  • 跟大一的区别大概是,有很多事情选择一个人扛。有烦恼了,不会轻易的诉说,想着想着事情,就会好起来。因为很多事情说了并...
    渡狸酱阅读 1,040评论 0 0