问题
I have to ask again because no one answered my question before (my problem is NOT a duplicate of How to draw a path on an Android canvas with animation?). Please read it carefully and help me, if possible by providing code. The abouve example is unclear for me, and the Path is created on the flow of drawing. This is NOT what I am looking for...
I want to draw ONE Path, that already exist in my View class, by drawing its points with time interval, to simulate an animation. How should I modify my onDraw class to archive it?
public void onDraw(Canvas canvas) {
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(6);
paint.setColor(Color.parseColor("#10BCC9"));
if(path != null && !path.isEmpty())
canvas.drawPath(path, paint);
}
I think it is simple question and I don't belive there is no simple answer... Please help...
回答1:
I found out that there is no solution for drawing a Path
with the time interval. My walk around solution is this one, where I reset my path path and create it again from Point array. i and j are global variables:
public void onDraw(Canvas canvas) {
if (i < strokes.length && j < strokes[i].length)
{
if (i == 0 && j == 0)
{
path.reset();
path.moveTo(strokes[0][0].x, strokes[0][0].y);
}
if(j == 0)
strokePaint.setColor(Color.RED);
else
strokePaint.setColor(Color.parseColor("#10BCC9"));
path.lineTo(strokes[i][j].x, strokes[i][j].y);
canvas.drawPath(path, strokePaint);
for(int k = 0; i < textCords.size() && k <= i ; k++)
canvas.drawText(String.valueOf(k+1), textCords.get(k).x, textCords.get(k).y, textPaint);
if (j == strokes[i].length-1)
{
i++;
j = 0;
if (i < strokes.length)
path.moveTo(strokes[i][0].x, strokes[i][0].y);
}
else
j++;
if (i < strokes.length)
{
postInvalidateDelayed(5);
}
else
{
i = 0;
j = 0;
animation = false;
}
}
}
I hope it will help someone...
来源:https://stackoverflow.com/questions/16703666/draw-a-path-as-animation-on-canvas