我不得不再问一次,因为之前没有人回答过我的问题(我的问题不是 How to draw a path on an Android canvas with animation? 的重复)。请仔细阅读并帮助我,如果可能的话,请提供代码。上面的例子我不清楚,路径是在绘图的流程上创建的。这不是我要找的...
我想绘制一条路径,它已经存在于我的 View 类中,通过按时间间隔绘制它的点来模拟动画。我应该如何修改我的 onDraw 类以将其存档?
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);
}
我认为这是一个简单的问题,我不相信没有简单的答案...请帮忙...
最佳答案
我发现没有用时间间隔绘制Path
的解决方案。我的绕行解决方案是这个,我在其中重置我的路径路径并从 Point 数组重新创建它。 i 和 j 是全局变量:
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;
}
}
}
我希望它能帮助某人...
关于java - 在 Canvas 上绘制路径作为动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16703666/