
主要涉及:畫(huà)圓弧、畫(huà)文字
記錄每一個(gè)結(jié)束時(shí)的角度,下一次開(kāi)始的角度即為上次結(jié)束時(shí)的角度。
主要代碼:
//計(jì)算每一個(gè)pie的角度f(wàn)loat startAngle = 0;//開(kāi)始的角度f(wàn)or (PieData data : pieData) { //將每一部分的圓弧畫(huà)出來(lái) mPaint.setColor(data.getPieColor());//每一塊的顏色 float swipeAngle = data.getPiePRoportion() * 360;//每一塊占多少角度 canvas.drawArc(bigRect, startAngle, swipeAngle, true, mPaint); ...}計(jì)算文本的位置 小圓半徑 設(shè)為大圓半徑的2/3

主要代碼:
//畫(huà)文本float x0 = width / 2;float y0 = height / 2;float txtAngle = startAngle + swipeAngle / 2;double radians = Math.toRadians(txtAngle);double x1 = x0 + Math.cos(radians) * smallRadius;double y1 = y0 + Math.sin(radians) * smallRadius;Rect textRect = new Rect();String pieName = data.getPieName();mPaint.getTextBounds(pieName, 0, pieName.length(), textRect);x1 = x1 - textRect.width() / 2;y1 = y1 + textRect.height() / 2;mPaint.setColor(data.getPieTxtColor());mPaint.setTextSize(TranslateDimensionUtils.sp2px(mContext, data.getPieTextSize()));canvas.drawText(pieName, (float) x1, (float) y1, mPaint);代碼: https://github.com/WhatWeCan/customer_views/tree/master/PieView
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注