項(xiàng)目里面的需求,當(dāng)時(shí)搜索到MPAndroidChart庫(kù),可以實(shí)現(xiàn),但是只是一個(gè)需求就引用偌大的一個(gè)庫(kù),感覺不太爽,打算自己自定義一個(gè)。

一、慣例先上效果圖
二、GitHub
代碼地址,歡迎指正https://github.com/MNXP/XPPieChart
三、思路
1、空心圖(一個(gè)大圓中心繪制一個(gè)小圓)
2、根據(jù)數(shù)據(jù)算出所占的角度
3、根據(jù)動(dòng)畫獲取當(dāng)前繪制的角度
4、根據(jù)當(dāng)前角度獲取Paint使用的顏色
5、動(dòng)態(tài)繪制即將繪制的 和 繪制已經(jīng)繪制的部分(最重要)
四、實(shí)現(xiàn)
1、空心圖(一個(gè)大圓中心繪制一個(gè)小圓)初始化數(shù)據(jù)
paint = new Paint();
paint.setAntiAlias(true);
paint.setStyle(Paint.Style.FILL_AND_STROKE);
screenW = DensityUtils.getScreenWidth(context);
int width = DensityUtils.dip2px(context, 15);//圓環(huán)寬度
int widthXY = DensityUtils.dip2px(context, 10);//微調(diào)距離
int pieCenterX = screenW / 2;//餅狀圖中心X
int pieCenterY = screenW / 3;//餅狀圖中心Y
int pieRadius = screenW / 4;// 大圓半徑
//整個(gè)餅狀圖rect
pieOval = new RectF();
pieOval.left = pieCenterX - pieRadius;
pieOval.top = pieCenterY - pieRadius + widthXY;
pieOval.right = pieCenterX + pieRadius;
pieOval.bottom = pieCenterY + pieRadius + widthXY;
//里面的空白rect
pieOvalIn = new RectF();
pieOvalIn.left = pieOval.left + width;
pieOvalIn.top = pieOval.top + width;
pieOvalIn.right = pieOval.right - width;
pieOvalIn.bottom = pieOval.bottom - width;
//里面的空白畫筆
piePaintIn = new Paint();
piePaintIn.setAntiAlias(true);
piePaintIn.setStyle(Paint.Style.FILL);
piePaintIn.setColor(Color.parseColor("#f4f4f4"));
文章題目:Android動(dòng)態(tài)繪制餅狀圖的示例代碼-創(chuàng)新互聯(lián)
標(biāo)題鏈接:http://chinadenli.net/article10/ceodgo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、移動(dòng)網(wǎng)站建設(shè)、動(dòng)態(tài)網(wǎng)站、網(wǎng)站策劃、建站公司、網(wǎng)站營(yíng)銷
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容