Android使用drawPath和drawRoundRect绘制rect round,结果不同

时间:2017-05-05 12:02:08

标签: android android-canvas android-drawable

当我在android中绘制路径时,线条似乎太薄了。所以我做了一个实验: 使用drawPath并使用drawRoundRect绘制圆形矩形。 这是我的代码:

//setPaint
mStrokeWidth = 1;
mPaint.setStrokeWidth(mStrokeWidth);
mPaint.setColor(Color.RED);
mPaint.setAntiAlias(true);   
mPaint.setStyle(Paint.Style.STROKE);

//draw using drawRoundRect
mStrokeWidth = 1;

@Override
public void draw(Canvas canvas) {
    Rect bounds = getBounds();
    mRect.set(bounds.left + mStrokeWidth / 2,
                  bounds.top + mStrokeWidth / 2,
                  bounds.right - mStrokeWidth / 2,
                  bounds.bottom - mStrokeWidth / 2
                );
    canvas.drawRoundRect(mRect, 10, 10, mPaint);
}

//draw using drawPath
mStrokeWidth = 1;

@Override
public void draw(Canvas canvas) {
      Rect bounds = getBounds();
      mRect.set(bounds.left + mStrokeWidth / 2,
                      bounds.top + mStrokeWidth / 2,
                      bounds.right - mStrokeWidth / 2,
                      bounds.bottom - mStrokeWidth / 2
                    );
      Path path = new Path();
      path.addRoundRect(mRect, 10, 10, Path.Direction.CCW);
      canvas.drawPath(path, mPaint);
}

结果如下:

enter image description here

左边是使用drawRoundRect,右边是使用drawPath 你可以看到左边比右边厚。我想知道是什么原因造成的?

0 个答案:

没有答案