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);


}
---------------------
作者:若塵風
來源:CSDN
原文:https://blog.csdn.net/liuzhi0724/article/details/44461945
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM