绘制路径的画布动画画布、路径、动画

2023-09-06 10:30:45 作者:上帝说一定要长长长长

我有,因为没有人面前回答我的问题再问一遍(我的问题不是How绘制路径的Andr​​oid的画布上用动画?)。请仔细阅读并帮助我,如果有可能通过提供code。该abouve例子不清我,对绘画的流动创建的路径。这不是我期待的...

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...

我想用时间间隔拉分点画出一条路径,已经在我的视图类存在,以模拟动画。我应该如何修改我的onDraw类归档?

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...

推荐答案

我发现有用于绘制路径的时间间隔无解。我身边的解决方案走的是这一次,在那里我从点阵列再次重置我的道路路径和创建它。 i和j是全局变量

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:

公共无效的onDraw(帆布油画){

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...