canvas.drawRoundRect方法,绘制圆角矩形

public void drawRoundRect (RectF rect, float rx, float ry, Paint paint)
Draw the specified round-rect using the specified paint. The roundrect will be filled or framed based on the Style in the paint.


Parameters
rect The rectangular bounds of the roundRect to be drawn
rx The x-radius of the oval used to round the corners
ry The y-radius of the oval used to round the corners
paint The paint used to draw the roundRect


【功能说明】该方法用于在画布上绘制圆角矩形,通过指定RectF对象以及圆角半径来实现。该方法是绘制圆角矩形的主要方法,同时也可以通过设置画笔的空心效果来绘制空心的圆角矩形。
【基本语法】public void drawRoundRect (RectF rect, float rx, float ry, Paint paint)
参数说明
rect:RectF对象。
rx:x方向上的圆角半径。
ry:y方向上的圆角半径。
paint:绘制时所使用的画笔。


protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
//新建一只画笔,并设置为绿色属性
Paint _paint = new Paint();
_paint.setColor(Color.GREEN);
//新建矩形r1
RectF r1 = new RectF();
r1.left = 50;
r1.right = 250;
r1.top = 50 ;
r1.bottom = 150;

//新建矩形r2
RectF r2 = new RectF();
r2.left = 50;
r2.right = 250;
r2.top = 200 ;
r2.bottom = 300;

//画出矩形r1
canvas.drawRect(r1, _paint);
//画出圆角矩形r2
_paint.setColor(Color.rgb(204, 204, 204));
canvas.drawRoundRect(r2, 10, 10, _paint);


}
  • 2
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值