这个demo是鸣人叫我做的效果,大家用的时候根据实际需要再调整参数。
先看效果图:
主要构思:当progress到最大值的时候触发动画效果,效果都由canvas画布上进行。
主要代码:
@Override protected void onDraw(Canvas canvas) { int halfWidth = getWidth() / 2; int halfHeight = getHeight() /2; //this way to draw the path for progress if(progress<MAX_PROGRESS){ canvas.drawColor(COLOR_TRANSLUCENT); pRectF.top = halfHeight - RADIUS_PROGRESS; pRectF.bottom = halfHeight + RADIUS_PROGRESS; pRectF.left = halfWidth - RADIUS_PROGRESS; pRectF.right = halfWidth + RADIUS_PROGRESS; canvas.drawArc(pRectF, -90, ((float)progress/(float)MAX_PROGRESS)*360, false, pPaint); canvas.save(); //this way to draw the images when animation start }else{ int alter = progress-MAX_PROGRESS; Path path = new Path(); path.addRect(0, 0,getWidth(),getHeight(),Path.Direction.CW); path.addCircle(halfWidth, halfHeight,RADIUS_BIG_CIRCLE+alter*ALTER_LENTH,Path.Direction.CCW); canvas.drawPath(path, squarePaint); canvas.drawCircle(halfWidth, halfHeight, RADIUS_PROGRESS-alter*ALTER_LENTH, sCirclePaint); canvas.save(); } super.onDraw(canvas); }
P.S
感谢7heaven告诉Path的用法
下载地址 :https://github.com/arjinmc/ScaleProgressBar
时间: 2024-10-01 05:27:24