GcsSloop / AndroidNote

安卓学习笔记
http://www.gcssloop.com/#blog
9.17k stars 2.14k forks source link

关于多次addRect的问题 #65

Closed beilo closed 7 years ago

beilo commented 7 years ago
        canvas.translate(mCenterX, mCenterY);
        mPaint.setColor(Color.BLACK);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeWidth(5);
        canvas.drawLine(0, -mCenterY, 0, mCenterY, mPaint);
        canvas.drawLine(-mCenterX, 0, mCenterX, 0, mPaint);

        Path path = new Path();

        path.addRect(-100, -100, 100, 100, Path.Direction.CW);  // 添加小矩形
        path.addRect(-200, -200, 200, 200, Path.Direction.CW);  // 添加大矩形
        canvas.drawPath(path, mPaint);                    // 绘制 Path

        PathMeasure measure = new PathMeasure(path, false);     // 将Path与PathMeasure关联

        float len1 = measure.getLength();                       // 获得第一条路径的长度

        measure.nextContour();                                  // 跳转到下一条路径

        float len2 = measure.getLength();                       // 获得第二条路径的长度

        Log.i("LEN", "len1=" + len1);                              // 输出两条路径的长度
        Log.i("LEN", "len2=" + len2);`

页面

除非按照下面的写才没问题,请问为什么

        path.addRect(-100, -100, 100, 100, Path.Direction.CW);  // 添加小矩形
        path.addRect(-200, -200, 200, 200, Path.Direction.CCW);  // 添加大矩形