位于res/drawable/face.xml
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="200dp" android:width="200dp" android:viewportHeight="100" android:viewportWidth="100" > <path android:strokeColor="@android:color/holo_red_dark" android:fillColor="@color/yellow" android:pathData="@string/path_circle"/> <path android:fillColor="@android:color/black" android:pathData="@string/path_face_left_eye"/> <path android:fillColor="@android:color/black" android:pathData="@string/path_face_right_eye"/> <path android:name="mouth" android:strokeColor="@android:color/black" android:strokeWidth="@integer/stroke_width" android:strokeLineCap="round" android:pathData="@string/path_face_mouth_sad"/> </vector>
res/values/strings.xml
<string name="path_circle"> M 50,50 m -48,0 a 48,48 0 1,0 96,0 a 48,48 0 1,0 -96,0 </string> <string name="path_face_left_eye"> M 35,40 m -7,0 a 7,7 0 1,0 14,0 a 7,7 0 1,0 -14,0 </string> <string name="path_face_right_eye"> M 65,40 m -7,0 a 7,7 0 1,0 14,0 a 7,7 0 1,0 -14,0 </string> <string name="path_face_mouth_sad"> M 30,75 Q 50,55 70,75 </string> <string name="path_face_mouth_happy"> M 30,65 Q 50,85 70,65 </string>
参考文章: http://www.w3.org/TR/SVG/paths.html#PathData M是移动的意思,大写代表绝对坐标,小写是相对坐标,注意相对的对象是其前一个对象。 a是画弧,48,48分别是所画弧的x,y轴的半径,0是x轴偏移量,1是取大弧,0是逆时针,(96,0)是终点坐标。
下面的a同理。 <span style="font-family: Arial, Helvetica, sans-serif;">若将48全换成24,96全换成48,会看到圆的半径为原来的一半。 </span><span style="font-family: Arial, Helvetica, sans-serif;"> </span>