Android 圆角边框RoundRect原理 - Go语言中文社区

Android 圆角边框RoundRect原理


绘制圆角矩形的方法

 /**
     * Draw the specified round-rect using the specified paint. The roundrect will be filled or
     * framed based on the Style in the paint.
     *
     * @param rect The rectangular bounds of the roundRect to be drawn
     * @param rx The x-radius of the oval used to round the corners
     * @param ry The y-radius of the oval used to round the corners
     * @param paint The paint used to draw the roundRect
     */
    public void drawRoundRect(@NonNull RectF rect, float rx, float ry, @NonNull Paint paint) {
        super.drawRoundRect(rect, rx, ry, paint);
    }

该方法来自Canvas类,rect代表矩形,rxry分别代表形成圆角所需要的椭圆的x和y轴半径,那么rxry究竟如何形成圆角呢?

形成圆角的原理

矩形的四个圆角是分别生成的,以左上角的圆角为例:

首先通过rect绘制出矩形,然后以矩形的左上角定点为起点,分别向x和y轴平移rxry, 得到的点为中心,以rxry为x和y轴的半径绘制椭圆,椭圆的坐上半部分圆弧就是圆角了。如下图所示,图中第一个图形是根据圆角的原理用矩形和椭圆绘制的,第二个图形就是roundRect.

版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/Jaden_hool/article/details/80757072
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2021-05-29 16:31:14
  • 阅读 ( 571 )
  • 分类:

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢