FlyProgressView——仿Windows进度条

FlyProgressView

仿Windows进度条
下载地址:https://github.com/jerowang/FlyProgressView
主要功能:

1.设置点的颜色

2.设置背景颜色

3.设置点的间距

4.设置速度(待添加)



效果图:




使用示例代码:




FlyProgressView flyProgressView = (FlyProgressView) findViewById(R.id.fpv_main);
if (flyProgressView != null) {
    // 设置背景颜色颜色
    flyProgressView.setBackgroundColor(0xFF2A5699);
    // 设置点的半径
    flyProgressView.setPointRadius(DipUtils.dip2px(this, 5));
    // 设置间距,0表示默认为点的半径
    flyProgressView.setSplitWidth(DipUtils.dip2px(this, 0));
    // 设置点的颜色
    flyProgressView.setPointColor(0xFFFFFFFF);
//            停止动画用stop方法
//            flyProgressView.stop();
}

核心代码:




@Override
protected void onDraw(Canvas canvas) {
    if (checkStop()) {
        return;
    }
    currentDrawFrame++;
    int tempSpeed = currentDrawFrame;
    if (splitWidth <= pointRadius)
        splitWidth = pointRadius;
    if (currentDrawFrame < 0) {
        canvas.drawCircle(getMeasuredWidth() / 2f + tempSpeed * (-tempSpeed / 5f) + splitWidth * 4,
                getMeasuredHeight() / 2, pointRadius, pointPaint);
        canvas.drawCircle(getMeasuredWidth() / 2f + tempSpeed * (-tempSpeed / 4f) + splitWidth * 2,
                getMeasuredHeight() / 2, pointRadius, pointPaint);
        canvas.drawCircle(getMeasuredWidth() / 2f + tempSpeed * (-tempSpeed / 3f),
                getMeasuredHeight() / 2, pointRadius, pointPaint);
        canvas.drawCircle(getMeasuredWidth() / 2f + tempSpeed * (-tempSpeed / 2f) - splitWidth * 2,
                getMeasuredHeight() / 2, pointRadius, pointPaint);
        canvas.drawCircle(getMeasuredWidth() / 2f + tempSpeed * (-tempSpeed / 1f) - splitWidth * 4,
                getMeasuredHeight() / 2, pointRadius, pointPaint);
    } else {
        canvas.drawCircle(getMeasuredWidth() / 2f + tempSpeed * (tempSpeed / 1f) + splitWidth * 4,
                getMeasuredHeight() / 2, pointRadius, pointPaint);
        canvas.drawCircle(getMeasuredWidth() / 2f + tempSpeed * (tempSpeed / 2f) + splitWidth * 2,
                getMeasuredHeight() / 2, pointRadius, pointPaint);
        canvas.drawCircle(getMeasuredWidth() / 2f + tempSpeed * (tempSpeed / 3f),
                getMeasuredHeight() / 2, pointRadius, pointPaint);
        canvas.drawCircle(getMeasuredWidth() / 2f + tempSpeed * (tempSpeed / 4f) - splitWidth * 2,
                getMeasuredHeight() / 2, pointRadius, pointPaint);
        canvas.drawCircle(getMeasuredWidth() / 2f + tempSpeed * (tempSpeed / 5f) - splitWidth * 4,
                getMeasuredHeight() / 2, pointRadius, pointPaint);
    }
    if (currentDrawFrame == totalDrawFrame) {
        currentDrawFrame = -100;
    }
    invalidate();
}

你可能感兴趣的:(android,动画,windows,进度条,progress)