Skip to content

边框画不完整 #1

@sing1

Description

@sing1

当没有margin的时候你的边框会出现问题

这样画就可以了

private void drawBorder(Canvas canvas){
    if(borderWidth > 0){
        borderPath.reset();
        final int width = getWidth();
        final int height = getHeight();

        if (shapeType == 0) {
            final float halfBorderWidth = borderWidth * 0.5f;
            final float cx = width * 0.5f;
            final float cy = height * 0.5f;
            final float radius = Math.min(width, height) * 0.5f;
            borderPath.addCircle(cx, cy, radius - halfBorderWidth, Path.Direction.CW);
        } else {// 当ShapeType = 1 时 图片为圆角矩形
            final float halfBorderWidth = borderWidth * 0.35f;//乘以0.5会导致border在圆角处不能包裹原图
//                leftTopRadius = Math.min(leftTopRadius, Math.min(width, height) * 0.5f);
//                leftBottomRadius = Math.min(leftBottomRadius, Math.min(width, height) * 0.5f);
//                rightTopRadius = Math.min(rightTopRadius, Math.min(width, height) * 0.5f);
//                rightBottomRadius = Math.min(rightBottomRadius, Math.min(width, height) * 0.5f);
            RectF rect = new RectF(halfBorderWidth, halfBorderWidth, width - halfBorderWidth, height - halfBorderWidth);
            borderPath.addRoundRect(rect,
                        new float[]{radius, radius, radius, radius,
                                radius, radius, radius, radius},
                        Path.Direction.CW);
        }

        Paint paint = new Paint();
        paint.setStrokeWidth(borderWidth);
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(borderColor);
        paint.setAntiAlias(true);
        canvas.drawPath(borderPath, paint);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions