如上图所示,小球也需要随着圆弧的增长而不停地变化位置,保证一直处在圆弧顶点,,圆弧运动轨迹我已经画出来了,部分代码如下:
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int mWidth = getMeasuredWidth();
int mHeight = getMeasuredHeight();
float section = progressValue / 100;//progressValue是传进来的值,由定时器不停地发送过来
mPaint.setAntiAlias(true);//消除锯齿
mPaint.setStrokeWidth((float) 8);
mPaint.setStyle(Style.STROKE);
mPaint.setStrokeCap(Cap.ROUND);
rect.set(20, 20, mWidth - 20, mHeight - 20);
mPaint.setColor(Color.BLACK);
int count = mColors.length;
int[] colors = new int[count];
System.arraycopy(mColors, 0, colors, 0, count);
LinearGradient shader = new LinearGradient(3, 3, mWidth - 3, mHeight - 3, colors, null, Shader.TileMode.CLAMP);
mPaint.setShader(shader);
//画弧,第一个参数是RectF,第二个参数是角度的开始,第三个参数是多少度,第四个参数是真的时候画扇形,是假的时候画弧线
canvas.drawArc(rect, 90, section * 360, false, mPaint);}
|
|