android SVG 常用语法
Path指令
M = moveto(M X,Y) :将画笔移动到指定的坐标位置 L = lineto(L X,Y) :画直线到指定的坐标位置 H = horizontal lineto(H X):画水平线到指定的X坐标位置 V = vertical lineto(V Y):画垂直线到指定的Y坐标位置 C = curveto(C X1,Y1,X2,Y2,ENDX,ENDY):三次贝赛曲线 S = smooth curveto(S X2,Y2,ENDX,ENDY) Q = quadratic Belzier curve(Q X,Y,ENDX,ENDY):二次贝赛曲线 T = smooth quadratic Belzier curveto(T ENDX,ENDY):映射 A = elliptical Arc(A RX,RY,XROTATION,FLAG1,FLAG2,X,Y):弧线 Z = closepath():关闭路径
Path属性
path标签可用属性:
name:路径名称,可在其他地方引用,例如矢量图动画引用;
strokeWidth:线条宽度,单位为viewportHeight或viewportWidth中的1等分;。
strokeColor:线条颜色;
strokeAlpha:线条透明度。0f->1f;
strokeLineJoin:线条拐角的形状。圆角round、斜切尖角miter、斜角bevel,例如正方形的四个角;
strokeLineCap:线条线帽形状。圆角round、正方形square、臂butt;
strokeMiterLimit:斜线miter与strokeWidth的比例上限。如果比例值超过这个值,不再显示尖角而是bevel斜角。当strokeLineJoin属性设置为miter才生效。
fillColor:填充颜色;fillType:填充类型,取值nonZero、evenOdd;fillAlpha:填充透明度;trimPathStart:从路径开始位置剪掉比率的内容,留下剩下的,0f->1f;trimPathEnd:从路径开始位置截取比率的内容,留下截取的内容,0f->1f;trimPathOffset:trimPathStart或trimPathEnd的偏移量0f->1f;
例子
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24" android:tint="?attr/colorControlNormal"> <path android:fillColor="@android:color/white" android:pathData="M3,18 h18 v-2 L3,16 v2 z M3,13 h18 v-2 L3,11 v2 z M3,6 v2 h18 L21,6 L3,6 z"/> </vector>
解读例子
M3,18 将画笔移动到坐标(3,18);
h18从坐标(3,18)到坐标(21,18)画一条水平直线;
v-2从坐标(21,18)到坐标(21,16)画一条垂直直线;
L3,16从坐标(21,18)到坐标(3,16)画一条直线;
v2从坐标(3,16)到坐标(3,18)画一条垂直直线;
z 闭合起点和终点。
效果

