Android 圆角边框RoundRect原理
16lz
2021-01-23
绘制圆角矩形的方法
/** * 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
代表矩形,rx
和ry
分别代表形成圆角所需要的椭圆的x和y轴半径,那么rx
和ry
究竟如何形成圆角呢?
形成圆角的原理
矩形的四个圆角是分别生成的,以左上角的圆角为例:
首先通过rect
绘制出矩形,然后以矩形的左上角定点为起点,分别向x和y轴平移rx
和ry
, 得到的点为中心,以rx
和ry
为x和y轴的半径绘制椭圆,椭圆的坐上半部分圆弧就是圆角了。如下图所示,图中第一个图形是根据圆角的原理用矩形和椭圆绘制的,第二个图形就是roundRect.
更多相关文章
- canvas.drawRoundRect方法,绘制圆角矩形
- a64_7.1-v3.1android拉伸绘制矩形区域距离默认平板外边界问题
- android在java代码中绘制矩形框
- a64_7.1android平板关于更改绘制矩形界面透明度
- Android 圆角矩形ImageView
- Android 圆角矩形
- android 画虚线、实线,画圆角矩形,一半圆角
- 面试题5:椭圆里面有个内切圆,内切圆中有文字
- Android之圆角矩形