android - I want to follow the path of drawing dynamic curve,how to solve it? -
1、here chart:
2、here code:
private void drawcircle( canvas canvas, string content ){ mpath.addcircle(getwidth() / 2, getheight() / 2, mradius, direction.ccw); canvas.rotate(180, getwidth() / 2, getheight() / 2); canvas.drawtextonpath(content, mpath, 0, 0, mpaint); }
3、my problem how let circle 1 point 1 point display,not one-time display。i'm try use handler/thread/timer draw dynamic chart drawtextonpath , drawpath method, there show nothing.
you need use postdelayed() , add new character each time.
public class myview extends view { private path mpath = new path(); private float mradius = 100; private paint mpaint = new paint(); private string thewholetext = "abcdefghijklmnopqrstuvwxyz"; private string thecurrenttext = ""; private int = 0; private long frequency = 150; private runnable addcharacter = new runnable() { @override public void run() { thecurrenttext = thewholetext.substring(0, ++i); invalidate(); } }; public myview(context context, attributeset attrs, int defstyleattr) { super(context, attrs, defstyleattr); mpaint.setcolor(color.red); mpaint.settextsize(20); } public myview(context context, attributeset attrs) { this(context, attrs, 0); } public myview(context context) { this(context, null, 0); } private void drawcircle(canvas canvas, string content) { mpath.addcircle(getwidth() / 2, getheight() / 2, mradius, path.direction.ccw); canvas.rotate(180, getwidth() / 2, getheight() / 2); canvas.drawtextonpath(content, mpath, 0, 0, mpaint); } @override protected void ondraw(canvas canvas) { drawcircle(canvas, thecurrenttext); if (thecurrenttext.length() < thewholetext.length()) postdelayed(addcharacter, frequency); } }
please mark correct answer if works out you!
Comments
Post a Comment