Pra*_*ash 1 android paint android-canvas
我想在画布上作画
我如何在中心的 android 画布上绘制它?我尝试使用canvas.drawLine但没有得到所需的输出
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint(Paint.DITHER_FLAG);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(50);
paint.setColor(0xFF2287BB);
paint.setStrokeJoin(Paint.Join.MITER);
canvas.drawPath(createCornersPath(getWidth()/2 - 500, getHeight()/2 - 500, getWidth()/2 +500, getHeight()/2 + 500, 150), paint);
}
private Path createCornersPath(int left, int top, int right, int bottom, int cornerWidth){
Path path = new Path();
path.moveTo(left, top + cornerWidth);
path.lineTo(left, top);
path.lineTo(left + cornerWidth, top);
path.moveTo(right - cornerWidth, top);
path.lineTo(right, top);
path.lineTo(right , top + cornerWidth);
path.moveTo(left, bottom - cornerWidth);
path.lineTo(left, bottom);
path.lineTo(left + cornerWidth, bottom);
path.moveTo(right - cornerWidth, bottom);
path.lineTo(right, bottom);
path.lineTo(right, bottom - cornerWidth);
return path;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1399 次 |
| 最近记录: |