Draw a Path as animation on canvas

荒凉一梦 提交于 2019-12-01 11:39:10
Marek

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!