PieChart 扇形中间位置限制文字计算
private void drawPieChart(Canvas canvas) {
int centerX = getWidth() / 2;
int centerY = getHeight() / 2;
mPaint.setColor(mWrongColor);
mRectF.set(centerX - mRadius, centerY - mRadius, centerX + mRadius, centerY + mRadius);
float wrongPercent = mWrongPercent / 100f;
canvas.drawArc(mRectF, mStartAngle, wrongPercent * 360 * mAnimaProgress, true, mPaint);
if (!mAnimatorEnd) return;
float textAngle = wrongPercent * (float) Math.PI + mStartRad;
mPaint.setColor(Color.WHITE);
mPaint.setTextAlign(Paint.Align.CENTER);
mPaint.setTextSize(mTextSize);
mPaint.setFakeBoldText(true);
float startX, startY;
if (mWrongPercent > 0) {
startX = (float) (centerX + mRadius / 2 * Math.cos(textAngle));
startY = (float) (centerY + mRadius / 2 * Math.sin(textAngle)) + mTextSize / 2;
canvas.drawText(mWrongPercent + "", startX, startY, mPaint);
}
textAngle = (float) Math.PI * (1 + wrongPercent) + mStartRad;
startX = (float) (centerX + mRadius / 2 * Math.cos(textAngle));
startY = (float) (centerY + mRadius / 2 * Math.sin(textAngle)) + mTextSize / 2;
canvas.drawText((100 - mWrongPercent) + "", startX, startY, mPaint);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
上一篇: Android 悬浮窗
下一篇: 彻底找到 Tomcat 启动速度慢的元凶
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论