绘制圆角矩形的方法

 /**     * 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.

更多相关文章

  1. canvas.drawRoundRect方法,绘制圆角矩形
  2. a64_7.1-v3.1android拉伸绘制矩形区域距离默认平板外边界问题
  3. android在java代码中绘制矩形框
  4. a64_7.1android平板关于更改绘制矩形界面透明度
  5. Android 圆角矩形ImageView
  6. Android 圆角矩形
  7. android 画虚线、实线,画圆角矩形,一半圆角
  8. 面试题5:椭圆里面有个内切圆,内切圆中有文字
  9. Android之圆角矩形

随机推荐

  1. Android(安卓)Studio V3.12环境下TV开发
  2. Android(安卓)UI 组件开源软件 共有47款
  3. [Digging] android:fitsSystemWindows
  4. Android(安卓)实现倒计时的简单方式
  5. Android中关于Volley的使用(二)加载Json数
  6. Android中的界面去除标题和实现全屏的两
  7. android 兼容性测试 CTS 测试过程(实践测
  8. xUtils 源码解析
  9. proguard rule 惨痛教训(记录)
  10. 安全性“Crypto”提供程序在Android(安卓