ScaleProgressBar Loading效果

這個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

技術交流QQ羣:452472392


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章