我怎么画一个长方形的四角只在Android的画布

问题描述:

我想画的画布我怎么画一个长方形的四角只在Android的画布

enter image description here

我如何绘制在Android画布上的中心呢? 我尝试使用canvas.drawLine但没有得到期望的输出

+0

试试这个:https://stackoverflow.com/questions/45632822/android-how-to-draw-a-transparent -rectangle-镶上形状与 - 仅其通corne –

Image

@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; 
    }