CircularCounter 双层原形进度条,根据数据的变化而增减的,支持逆向旋转。
本项目主要由CircularCounter自定义控件实现, CircularCounter extends View,
主要由如下代码画出:
@Override
?? ?protected void onDraw(Canvas canvas) {
?? ??? ?super.onDraw(canvas);
?? ??? ?canvas.drawCircle(mBackgroundCenter, mBackgroundCenter,
?? ??? ??? ??? ?mBackgroundRadius, mBackgroundPaint);
?? ??? ?canvas.drawArc(mOneBounds, START_DEGREES, mOneDegrees, false, mOnePaint);
?? ??? ?canvas.drawArc(mTwoBounds, START_DEGREES, mTwoDegrees, false, mTwoPaint);
?? ??? ?canvas.drawArc(mThreeBounds, START_DEGREES, mThreeDegrees, false,
?? ??? ??? ??? ?mThreePaint);
?? ??? ?canvas.drawText(Integer.toString(mOneValue), mOneBounds.centerX(),
?? ??? ??? ??? ?mTextPosY, mTextPaint);
?? ??? ?canvas.drawText(mMetricText, mOneBounds.centerX(), mMetricPosY,
?? ??? ??? ??? ?mMetricPaint);
?? ?}
?? ?
进度值变化设置:
/*
?? ? * Setters
?? ? *
?? ? */
?? ?/**
?? ? * Set the next values to be drawn
?? ? * @param v1
?? ? * @param v2
?? ? * @param v3
?? ? */
?? ?public void setValues(int v1, int v2, int v3) {
?? ??? ?if (v1 <= mRange)
?? ??? ??? ?mOneDegrees = Math.round(((float) v1 * 360) / mRange);
?? ??? ?else
?? ??? ??? ?mOneDegrees = 360;
?? ??? ?if (v2 <= mRange)
?? ??? ??? ?mTwoDegrees = Math.round(((float) v2 * 360) / mRange);
?? ??? ?else
?? ??? ??? ?mTwoDegrees = 360;
?? ??? ?if (v3 <= mRange)
?? ??? ??? ?mThreeDegrees = Math.round(((float) v3 * 360) / mRange);
?? ??? ?else
?? ??? ??? ?mThreeDegrees = 360;
?? ??? ?mOneValue = v1;
?? ??? ?mSpinHandler.sendEmptyMessage(0);
?? ?}
???
原文:http://3263740861.iteye.com/blog/2249265