为for循环中绘制的每个路径设置动画

时间:2018-05-29 05:27:26

标签: android android-canvas

我正在使用画布绘制路径。在绘制4个或更多路径时。动画适用于单个路径但不适用于'for循环'。 当我使用Object Animator时,路径会被连接起来我想用动画绘制单独的路径。

绘制路径的代码

for (int i = 0; i < 6; i++) {
            Log.v("x", "" + i + ": " + x[i]);
            Log.v("y", "" + i + ": " + y[i])
           mPath.quadTo(x0,y0, x[i],y[i]);

        PathMeasure measure = new PathMeasure(path, false);
        length = measure.getLength();
       ObjectAnimator animator = ObjectAnimator.ofFloat(PathView.this, 
       "phase", 1.0f, 0.0f);
        animator.setDuration(3000);
        setPhase(length);
        animator.start();
        canvas.drawPath(mPath, mPaint);

            }
 public void setPhase(float phase)
    {
        Log.d("pathview","setPhase called with:" + String.valueOf(phase));
        paint.setPathEffect(createPathEffect(length, phase, 0.0f));

    }
public Paint getDashLine() {
        Paint fgPaintSel = new Paint();
        // fgPaintSel.setARGB(255, 255, 255,255);
        fgPaintSel.setColor(Color.WHITE);
        //fgPaintSel.setAlpha(120);

        fgPaintSel.setStrokeWidth(3);
        fgPaintSel.setStyle(Paint.Style.STROKE);


        fgPaintSel.setPathEffect(new DashPathEffect(new float[]{20, 20}, 0));


        return fgPaintSel;
    }

如何使用动画绘制每个路径。

0 个答案:

没有答案