先看一下效果图
随着时间的变化,圆弧增长的同时,圆弧顶点的圆球也跟着增长.
上代码,注释很详细:
自定义view类
public class CircleProgressView extends View {
/**
* 直径
*/
private int mDiameter;
/**
* 绘制时控制绘制的范围
*/
private Paint mPaint;
private float progressValue = 0;
RectF rect;
public CircleProgressView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public CircleProgressView(Context context) {
this(context, null);
}
/**
* 获得自定义的样式属性
*
* @param context
* @param attrs
* @param defStyle
*/
public CircleProgressView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CircleProgressView, defStyle, 0);
int n = a.getIndexCount();
for (int i = 0; i < n; i++) {
int attr = a.getIndex(i);
switch (attr) {
case R.styleable.CircleProgressView_diameter:
// 默认设置为40dp
mDiameter = a.getDimensionPixelSize(attr, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 40, getResources().getDisplayMetrics()));
break;
}
}
a.recycle();
mPaint = new Paint();
rect = new RectF();
progressValue = 0;
}
public void setProgressValue(float progressValue) {
this.progressValue = progressValue;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = 0;
int height = 0;
//设置直径的最小值
if (mDiameter <=