Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

边框画不完整 #1

Open
sing1 opened this issue Dec 27, 2016 · 2 comments
Open

边框画不完整 #1

sing1 opened this issue Dec 27, 2016 · 2 comments

Comments

@sing1
Copy link

sing1 commented Dec 27, 2016

当没有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);
    }
}
@lzan13
Copy link
Owner

lzan13 commented Dec 27, 2016

这个当时没有考虑这么细,感谢提醒

@sing1
Copy link
Author

sing1 commented Dec 27, 2016

https://github.com/Sing1/Util/blob/master/explain/RoundImageView.md
已经盗走 ^-^

@sing1 sing1 changed the title 边框花不完整 边框画不完整 Dec 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants