当我在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);
}
结果如下:
左边是使用drawRoundRect,右边是使用drawPath 你可以看到左边比右边厚。我想知道是什么原因造成的?