這是一個(gè)畫(huà)板的意思 要配合paint (畫(huà)筆)一起使用
首先創(chuàng)建出來(lái)畫(huà)筆
paint.setStyle(Paint.Style.STROKE);? ?設(shè)置樣式代表的是空心的? 只有輪廓
paint.setStyle(Paint.Style.FILL); 設(shè)置樣式代表的實(shí)心的,里面是有顏色的
mpaint.setAntiAlias(true); 支持抗鋸齒
mpaint.setStrokeWidth(3);?? 設(shè)置的是線條的粗細(xì)
canvas 的具體使用
畫(huà)圓 :
canvas .drawCircle(width/2,width/2,width/2-5,mpaint); 第一個(gè)是X軸的坐標(biāo),第二個(gè)是Y軸的坐標(biāo),第三個(gè)是半徑 第四個(gè)是畫(huà)筆
畫(huà)扇形
在畫(huà)扇形之前首先先創(chuàng)建一個(gè)類 RectF 來(lái)確定要畫(huà)的區(qū)域
RectF rectF = new RectF(0,0,width,width);
canvas.drawArc(扇形的區(qū)域毒涧,開(kāi)始角度蝙叛,角度硅瞧,是否顯示圓心礼烈,畫(huà)筆)
設(shè)置字到扇形
mpaint.setTextSize(24);設(shè)置畫(huà)筆的字體大小
先創(chuàng)建一個(gè)path?
Path path =new Path();
給path 添加屬性
path.addArc(位置,開(kāi)始的角度,每組字占的角度);
寫(xiě)字
canvas.drawTextOnPath(所要寫(xiě)的字,path,50,50,畫(huà)筆);
在Canvas 中添加點(diǎn)擊事件
1.先實(shí)現(xiàn)點(diǎn)擊監(jiān)聽(tīng)方法
2.在方法中實(shí)現(xiàn)就好了
點(diǎn)擊旋轉(zhuǎn)隨機(jī)數(shù)
Random random =new Random();
//? ? ? ? 獲取旋轉(zhuǎn)的隨機(jī)數(shù)
? ? ? ? int dul = random.nextInt(1000);
//? ? ? ? 第一個(gè)開(kāi)始的角度 摊滔,第二個(gè) 結(jié)束的角度,
? ? ? ? RotateAnimation rotateAnimation =new RotateAnimation(startjd,dul+360,width/2,width/2);
rotateAnimation.setDuration(1000);
rotateAnimation.setFillAfter(true);
startAnimation(rotateAnimation);
//? ? ? ? 動(dòng)畫(huà)結(jié)束后保存結(jié)束的位置版扩,在下次的時(shí)候就不回到原來(lái)的位置
? ? ? ? startjd =dul%360;
//? ? ? ? Toast.makeText(mcontext,"點(diǎn)擊了一下",Toast.LENGTH_SHORT).show();