Android中Paint類和Canvas類的方法匯總
Paint類的常用的方法
1.setColor方法,用于設(shè)置畫筆的顏色,
public void setColor(int color)//參數(shù)color為顏色值,也可以使用Color類定義的顏色
Color.BLACK:黑色
Color.BLUE:藍(lán)色
Color.CYAN:青綠色
Color.DKGRAY:灰黑色
Color.YELLOW:黃色
Color.GRAY:灰色
Color.GREEN:綠色
Color.LTGRAY:淺綠色
Color.MAGENTA:紅紫色
Color.TRANSPARENT:透明色
2.setAlpha方法,用于設(shè)置畫筆的透明度
public void setAlpha(int a )//參數(shù)a為透明度,其取值范圍為0~255,數(shù)值越小越透明
3.setStyle方法,用于設(shè)置畫筆的風(fēng)格,可以指定是圓心還是實(shí)心,該方法在矩形,圓形有明顯的效果
public void setStyle(Paint.Style style)//參數(shù)style為畫筆的風(fēng)格
Style.FILL:實(shí)心
Style.FILL_AND_STROKE:同時(shí)顯示實(shí)心和空心
Style.STROKE:空心
4.setStrokeWidth方法,用于設(shè)置畫筆的空心線寬,該方法在矩形,圓形,等圖形上有明顯的效果
public void setStrokeWidth(float width)//參數(shù)width為線寬,浮點(diǎn)型數(shù)據(jù)
5.setTextSize方法,用于設(shè)置畫筆的字體大小,主要用于繪制字符串
public void setTextSize(float textSize)//
6.setTypeface方法用于設(shè)置畫筆的字體樣式,可以使用系統(tǒng)自帶的字段,也可以使用自定義的字體
public void Typeface(Typeface typeface)//typeface為字體樣式
Typeface.DEFAULT:默認(rèn)字體
Typeface.DEFAULT_BOLD:加粗字體
Typeface.MONOSPACE:monospace字體
Typeface.SANS_SERIF:sans字體
Typeface.SERIF:serif字體
7.setTextScaleX方法.用于設(shè)置畫筆字體的比例因子,默認(rèn)為1,當(dāng)大于1時(shí)表示橫向拉伸,小于1時(shí)表示橫向壓縮
public void setTextScaleX(float scaleX)
8.setARGB方法,用于設(shè)置畫筆的顏色和透明度
public void setARGB(int a,int r,int g,int b);
參數(shù)a為透明度,范圍0~255
參數(shù)r為紅色的顏色值,范圍0~255
參數(shù)g為綠色的顏色值,范圍0~255
參數(shù)b為藍(lán)色的顏色值,范圍0~255
9.setUnderlineText方法,用于設(shè)置畫筆的下劃線
public void setUnderlineText(Boolean underlintext)
當(dāng)取值為true時(shí),表示顯示下劃線
10.setTextSkewX方法,用于設(shè)置畫筆的傾斜因子
public void setTextSkewX(float skewX)
參數(shù)skewX為傾斜因子,正數(shù)表示向左傾斜,負(fù)數(shù)表示向右傾斜
Canvas類的方法
1.public void drawColor(int color)
用于設(shè)置畫布的背景顏色
2.public void drawLine(float starX,float startY,float stopX,float stopY,Paint paint);
用于在畫布上繪制直線
參數(shù)分別為直線起點(diǎn)的X坐標(biāo),Y坐標(biāo),終點(diǎn)的X坐標(biāo),Y坐標(biāo),用到的畫筆
3.public void drawLines(float[] pts,Paint paint)
用于在畫布上繪制多條直線
參數(shù)pts為繪制直線的端點(diǎn)數(shù)組,每條直線占用4個(gè)數(shù)據(jù)
4.public void drawPoint(float x,float y,Paint paint)
用于在畫布上繪制點(diǎn)
參數(shù)為點(diǎn)的X,Y坐標(biāo),和所用的畫筆
5.public void drawPoints(float[] pts,Paint paint)
public void drawPoints(float[] pts,int offset,int count,Paint paint)
參數(shù)pts為繪制點(diǎn)的數(shù)組,每個(gè)點(diǎn)占用2個(gè)數(shù)據(jù)
參數(shù)offset為跳過的數(shù)據(jù)的個(gè)數(shù)
參數(shù)count為實(shí)際參與繪制的數(shù)據(jù)的個(gè)數(shù)
6.public void drawRect(Rect rect,Paint paint)
public void drawRect(RectF rect,Paint paint)
public void drawRect(float left,float float top,float right,float below,Paint paint)
用于繪制矩形
7.public void drawRoundRect(RectF rect,float rx,float ry,Paint paint)
用于繪制圓角矩形
rx為X方向上的圓角半徑
ry為Y方向上的圓角半徑
8.public void drawCircla(float cx,float cy,float radius, Paint paint)
用于在畫布上繪制圓形
cx為圓形的x坐標(biāo)
cy為圓形的y坐標(biāo)
rad為圓的的半徑
9.public void drawOval(RectF rect.Paint paint)
用于繪制橢圓
通過指定橢圓的外切矩形實(shí)現(xiàn)
10.public void drawPath(Path path,Paint paint)
用于在畫布上繪制任意多邊形來實(shí)現(xiàn)
11.public void drawArc(RectF oval,float startAngle,float sweepAngle,`Boolean usecenter,Paint p)
參數(shù)oval為圓弧所在的橢圓對象
startAngle為圓弧的起始角度,
sweepAngle為圓弧的角度,
useCenter表示是否顯示半徑連線,當(dāng)取值為true時(shí),顯示圓弧與圓心的半徑連線,
12,public void drawText(String text,float x,float y, Paint paint)
public void drawText(char[] text,int index,int count,float x,float y,Paint paint)
public void drawText(CharSequence text,int start,int end,float x,float y,Paint paint)
public void drawText(String text,int start,int end,float x,float y,Paint paint)
參數(shù)text為字符串的內(nèi)容,
x為X坐標(biāo)
y為Y坐標(biāo)
index為顯示的起始字符位置
count為顯示的字符個(gè)數(shù)
start為顯示的起始字符的位置
end為顯示的終止的字符的位置
13,public void drawBitmap(Bitmap bitmap,float left,float top,Paint paint)
參數(shù)bitmap為Bitmap對象,代表圖像資源,
left為圖像顯示的左邊的位置
right為圖像的顯示的右邊的位置
14,public int save()
用于鎖定畫布中的某一個(gè)或某幾個(gè)對象,用于鎖定對象操作的場合
使用sava方法鎖定畫布并完成操作之后,需要使用restore方法解除鎖定
15,public Boolean clipRect(Rect rect)
public Boolean clipRect(float left,float top,float right,float bottom)
public Boolean clipRect(int left,int top,int right,int boottom)
該方法用于裁剪畫布,設(shè)置畫布的顯示區(qū)域
16,public void rotate(float degrees)
public void rotate(float degrees,float px,float py)
用于旋轉(zhuǎn)畫布,通過旋轉(zhuǎn)畫布,可以將畫布上繪制的對象旋轉(zhuǎn)
參數(shù)degrees為旋轉(zhuǎn)的角度,正數(shù)為順時(shí)針方向,負(fù)數(shù)為逆時(shí)針方向
px為旋轉(zhuǎn)點(diǎn)的x坐標(biāo)
py為旋轉(zhuǎn)點(diǎn)的y坐標(biāo)
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時(shí)也希望多多支持腳本之家!
相關(guān)文章
Android應(yīng)用接入微信分享的實(shí)例代碼
本篇文章主要介紹了Android應(yīng)用接入微信分享的實(shí)例代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-07-07Android PhotoView使用步驟實(shí)例詳解
這篇文章主要介紹了Android PhotoView使用步驟實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-06-06Android開發(fā)筆記之:深入理解多線程AsyncTask
本篇文章是對Android中多線程AsyncTask進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05Flutter底部不規(guī)則導(dǎo)航的實(shí)現(xiàn)過程
這篇文章主要給大家介紹了關(guān)于Flutter底部不規(guī)則導(dǎo)航的實(shí)現(xiàn)過程,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用Flutter具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08Android利用Paint自定義View實(shí)現(xiàn)進(jìn)度條控件方法示例
這篇文章主要給大家介紹了關(guān)于Android利用Paint自定義View實(shí)現(xiàn)進(jìn)度條控件的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對各位Android開發(fā)者們具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-11-11如何使用Kotlin進(jìn)行Android開發(fā)
這篇文章主要教大家如何使用Kotlin進(jìn)行Android開發(fā),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05Android自定義View實(shí)現(xiàn)五子棋游戲
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)五子棋游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-11-11