我正在创建一个自定义 View ,它使用 Canvas 绘制一 strip 圆角的简单线条,但我无法使拐角处的线条与直线部分具有相同的厚度。 该路径在 onSizeChanged 方法中定义。
这就是我的 View :
这是 View
public class CanvasView extends View {
private Bitmap mBitmap;
private Canvas mCanvas;
private Path mPath;
private Paint mBitmapPaint;
Context context;
public CanvasView(Context c) {
super(c);
context = c;
mPath = new Path();
mBitmapPaint = new Paint(Paint.DITHER_FLAG);
}
public CanvasView(Context c, AttributeSet attrs) {
super(c, attrs);
context = c;
mPath = new Path();
mBitmapPaint = new Paint(Paint.DITHER_FLAG);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
if(mBitmap == null) {
RectF rectf = new RectF(w - w / 2, h - w / 2, w, h);
mPath.moveTo(w, 0);
mPath.lineTo(w, h - w / 2);
mPath.arcTo(rectf, 0, 90);
mPath.lineTo(0, h);
mBitmapPaint.setAntiAlias(true);
mBitmapPaint.setDither(true);
mBitmapPaint.setColor(context.getResources().getColor(R.color.siminn_warm_gray));
mBitmapPaint.setStyle(Paint.Style.STROKE);
mBitmapPaint.setStrokeWidth(5);
}
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
canvas.drawPath(mPath, mBitmapPaint);
}
}
最佳答案
我发现了,我是沿着 Canvas 的边缘绘制的,这样的效果是只显示了一半的线条。我将线条从边缘移动了一点,它正在工作
关于android - 在 Canvas 上绘图时,路径弧比线弧粗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54131989/