Code example for Canvas

Methods: drawCircle, drawLine, drawOval, drawRect, translate

0
		} 
 
		@Override 
		protected void onDraw(Canvas canvas) {
			// 移动中心 
			canvas.translate(mWidth / 2 - 50, mHeight / 2);
			// 画中心圆 
			canvas.drawCircle(0, 0, mCenterRadius, mCenterPaint);
			// 是否显示中心圆外的小圆环 
			if (mHighlightCenter || mlittleLightCenter) {
				int c = mCenterPaint.getColor();
				mCenterPaint.setStyle(Paint.Style.STROKE);
				if (mHighlightCenter) {
					mCenterPaint.setAlpha(0xFF);
				} else if (mlittleLightCenter) {
					mCenterPaint.setAlpha(0x90);
				} 
				canvas.drawCircle(0, 0,
						mCenterRadius + mCenterPaint.getStrokeWidth(),
						mCenterPaint);
 
				mCenterPaint.setStyle(Paint.Style.FILL);
				mCenterPaint.setColor(c);
			} 
			// 画色环 
			canvas.drawOval(new RectF(-mCircleRadius, -mCircleRadius,
					mCircleRadius, mCircleRadius), mCirclePaint);
			// 画黑白渐变块 
			if (mDownInCircle) {
				mRectColors[1] = mCenterPaint.getColor();
			} 
			mRectShader = new LinearGradient(0, mRectTop, 0, mRectBottom,
					mRectColors, null, Shader.TileMode.MIRROR);
			mRectPaint.setShader(mRectShader);
			canvas.drawRect(mRectLeft, mRectTop, mRectRight, mRectBottom,
					mRectPaint);
			float offset = mLinePaint.getStrokeWidth() / 2;
			canvas.drawLine(mRectLeft - offset, mRectTop - offset * 2,
					mRectLeft - offset, mRectBottom + offset * 2, mLinePaint);// 左
			canvas.drawLine(mRectLeft - offset * 2, mRectTop - offset,
					mRectRight + offset * 2, mRectTop - offset, mLinePaint);// 上
			canvas.drawLine(mRectRight + offset, mRectTop - offset * 2,
					mRectRight + offset, mRectBottom + offset * 2, mLinePaint);// 右
			canvas.drawLine(mRectLeft - offset * 2, mRectBottom + offset,
					mRectRight + offset * 2, mRectBottom + offset, mLinePaint);// 下
			super.onDraw(canvas);
		} 
 
		@Override