美文网首页
Android VectorDrawable的理解笔记

Android VectorDrawable的理解笔记

作者: Jinkia | 来源:发表于2016-03-27 20:14 被阅读0次

    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 VectorDrawable的理解笔记

          本文链接:https://www.haomeiwen.com/subject/shgdlttx.html