在drawable目录下创建一个vector文件.
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="20dp"
android:height="20dp"
android:viewportHeight="300"
android:viewportWidth="300"
>
<path android:fillColor="#850fbf"
android:pathData="m64.1825,142.57981l11.74545,
-32.13762l30.74983,-19.86238l38.00946,0l30.75002,
19.86238l11.74526,32.13762l-11.74526,32.13762l-30.75002,19.
86237l-38.00946,0l-30.74983,-19.86237l-11.74545,-32.13762z"
></path>
</vector>
其中 width 和 height 是指图形的宽高, viewportHeight 和 viewportWidth 是画布的宽高
fillcolor 是指图形内部填充的颜色
pathData 就是整个绘制的过程.
可以通过 editor.method.ac(链接) 进行绘制,然后获取pathData里面的数据,直接复制即可.
获取方法: 绘制完成后,在Method Draw 这个工具的导航栏里面点击view, source,可以看到整个绘制过程
<svg width="580" height="400" xmlns="http://www.w3.org/2000/svg">
<!-- Created with Method Draw - http://github.com/duopixel/Method-Draw/ -->
<g>
<title>background</title>
<rect fill="#fff" id="canvas_background" height="402" width="582" y="-1" x="-1"/>
<g display="none" overflow="visible" y="0" x="0" height="100%" width="100%" id="canvasGrid">
<rect fill="url(#gridpattern)" stroke-width="0" y="0" x="0" height="100%" width="100%"/>
</g>
</g>
<g>
<title>Layer 1</title>
<path stroke="#000" id="svg_1" d="m489.099,199.26264c-8.72741,-1.31785 -15.44933,-9.09971 -13.51485,-17.42803c2.29022,-10.99178 13.00256,-18.73926 23.50181,-23.04114c8.49242,-3.22194 18.8659,-3.75608 26.944,0.75939c0.32184,-52.90159 0.1409,-105.80539 0.18862,-158.70799c2.85079,-0.11319 6.11636,-0.66628 5.33823,3.06911c0.23162,8.80807 5.84319,16.23586 12.81524,21.74629c14.8103,12.71897 31.22857,27.43257 32.5336,47.35382c1.39557,7.80472 -3.09831,15.48645 -1.19559,23.06286c1.81621,7.46771 1.27474,15.21985 0.12766,22.72589c5.39353,13.47176 4.09115,28.98281 -1.78468,42.13736c0.54278,4.11108 -9.90773,10.81816 -5.32987,3.96664c6.18152,-12.49637 9.43333,-27.86569 2.72993,-40.72447c-8.11846,-12.46287 -22.89243,-18.85306 -35.00699,-27.36194c-8.43214,-7.91076 -3.88676,7.45962 -5.14293,12.04163c-0.18746,22.47674 -0.20228,44.95429 -0.29407,67.43147c-3.77524,8.56252 -10.70002,15.81179 -19.92267,19.52883c-6.76119,2.93979 -14.52874,4.88331 -21.98744,3.44027l-0.00001,0zm82.23478,-96.89487c-5.22521,-17.45623 -21.849,-29.28703 -38.07797,-37.81337c-4.44257,-0.5787 1.31714,9.43557 2.56522,12.53667c5.81276,10.61801 17.25934,16.88557 25.51351,25.65511c3.60085,2.77884 7.69987,8.51307 10.50996,10.0471c0.40832,-3.45895 0.1611,-7.00696 -0.51071,-10.42552l-0.00001,0.00001zm0.6574,-23.81235c-0.0827,-14.67214 -11.91356,-26.36706 -23.38047,-35.09938c-5.34665,-3.29623 -11.8124,-8.84663 -17.30369,-9.51213c1.04503,8.16713 4.97588,16.16475 12.19686,21.17411c10.27346,9.28722 21.13494,18.55114 28.26307,30.21451c0.82058,-2.02755 0.09387,-4.61395 0.22423,-6.77712z" stroke-width="1.5" fill="#fff"/>
</g>
</svg>
把其中的计算过程复制到项目的pathData 里面即可完成绘制,