本文主要介绍VectorDrawable中一些常见属性的含义,和patchData中某些英文字母代替的意义:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="64dp"
android:width="64dp"
android:viewportHeight="600"
android:viewportWidth="600" >
<group
android:name="rotationGroup"
android:pivotX="300.0"
android:pivotY="300.0"
android:rotation="45.0" >
<path
android:name="v"
android:fillColor="#000000"
android:pathData="M300,70 l 0,-70 70,70 0,0 -70,70z" />
</group>
</vector>
vector
- android:name 定义该drawable的名字
- android:width 定义该 drawable的内部(intrinsic)宽度,即drawable_with的绝对大小,支持所有 Android 系统支持的尺寸,通常使用dp
- android:height 定义该drawable 的内部(intrinsic)高度,即drawable_height的绝对大小,其它同上
- android:viewportWidth 定义矢量图视图的宽度,即pathdata中的路径不能超过这个范围
- android:viewportHeight 定义矢量图视图的高度,同上
- android:tint 定义该 drawable 的 tint 颜色。默认是没有
- android:tintMode定义 tint 颜色的 Porter-Duff blending 模式,图像混合模式,默认值为 src_in
- android:autoMirrored设置当系统为 RTL (right-to-left) 布局的时候,是否自动镜像该图片。比如 阿拉伯语
- android:alpha 该图片的透明度属性
group
- android:name 定义 group 的名字
- android:rotation 定义该 group 的路径旋转多少度显示
- android:pivotX 定义缩放和旋转该 group 时候的 X 参考点。该值相对于 vector 的 viewport值来指定的
- android:pivotY 定义缩放和旋转该 group 时候的 Y 参考点。该值相对于 vector 的viewport 值来指定的
- android:scaleX 定义 X 轴的缩放倍数
- android:scaleY 定义 Y 轴的缩放倍数
- android:translateX 定义移动 X 轴的位移。相对于 vector 的viewport 值来指定的
- android:translateY 定义移动 Y 轴的位移。相对于 vector 的 viewport 值来指定的
path
- android:name 定义该 path 的名字,这样在其他地方可以通过名字来引用这个路径 (比如动画中的引用)
- android:pathData 和 SVG中 d 元素一样的路径信息(图像)
- android:fillColor 定义填充路径的颜色,(即路径内区域的颜色)如果没有定义则不填充路径
- android:strokeColor 定义如何绘制路径边框,(即画图线的颜色)如果没有定义则不显示边框
- android:strokeWidth 定义路径边框的粗细尺寸
- android:strokeAlpha 定义路径边框的透明度
- android:fillAlpha 定义填充路径颜色的透明度
- android:trimPathStart 从路径起始位置截断路径的比率,取值范围从 0 到1
- android:trimPathEnd 从路径结束位置截断路径的比率,取值范围从 0 到1
- android:trimPathOffset 设置路径截取的范围 Shift trim region (allows showed region to include the start and end), in the range from 0 to 1
- android:strokeLineCap 设置路径线帽的形状,取值为 butt, round, square.
- android:strokeLineJoin设置路径交界处的连接方式,取值为 miter,round,bevel.
- android:strokeMiterLimit设置斜角的上限,Sets the Miter limit for a stroked path. 注:当strokeLineJoin设置为 “miter” 的时候,绘制两条线段以锐角相交的时候,所得的斜面可能相当长。当斜面太长,就会变得不协调。strokeMiterLimit属性为斜面的长度设置一个上限。这个属性表示斜面长度和线条长度的比值。默认是 10,意味着一个斜面的长度不应该超过线条宽度的 10倍。如果斜面达到这个长度,它就变成斜角了。当 strokeLineJoin 为 “round” 或 “bevel” 的时候,这个属性无效
android:pathData
- 大写和小写的区别:大写表示绝对路径,小写表示相对前一个点的相对路径
- M: move to 移动绘制点
- L:line to 直线
- Z:closepath 闭合
- H : horizontal lineto 水平移动
- V : vertical lineto 垂直移动
- C:cubic bezier 三次贝塞尔曲线(描述三个点)
- S :shorthand/smooth curveto 三次贝塞尔曲线(第一个点是上一个命令倒数第二个点以倒数第一个为中心的对称点,只描述二个点)
- Q:quatratic bezier 二次贝塞尔曲线(二个点)
- T : Shorthand/smooth quadratic Bézier curveto 二次贝塞尔曲线(只有结束点,其中有一个隐藏的对称点)
- <path d="M200,300 Q400,50 600,300 T1000,300"
- A:elliptical arc 椭圆(X半径,Y半径 沿X轴的旋转角度[负数逆时针,正数顺时针] 两点间画大弧“1”还是小弧“0”,两点间是逆时针“0”还是顺时针“1” X,Y(终点坐标))
<path d="M600,350 l 50,-25
a25,25 -30 0,1 50,-25 l 50,-25
a25,50 -30 0,1 50,-25 l 50,-25
a25,75 -30 0,1 50,-25 l 50,-25
a25,100 -30 0,1 50,-25 l 50,-25"
fill="none" stroke="red" stroke-width="5" />