android倒计时广告进度条

实现效果,如图

下载链接:http://download.csdn.net/download/chedandehuiyi/10225930

API:


/** * 设置进度条颜色 */cdp.setProgressColor(R.color.colorPrimary);/** * 进度条宽度 */cdp.setProgressWidth(20);/** * 起始角度 */cdp.setProgressType(CountDownProgress.ProgressType.RIGHT);/** * 内容 */cdp.setContentText("跳过广告");/** * 字体大小 */cdp.setContentTextSize(15);/** * 字体颜色 */cdp.setTextColor(R.color.colorPrimary);/** * 设置时间 */cdp.setmCountDownTime(3000);
/** * 点击事件和计时结束的监听 */cdp.setOnProgressListener(new OnProgressListener() {    @Override    public void onClick() {            }    @Override    public void onFinish() {    }});

实现原理:

 1、进度条的绘制:drawArc绘制圆弧,通过valueAnimator监听0到360度来改变绘制的范围角度

 

canvas.drawArc(mRextF,        mStartLocation,        progress,        false,        mPaint);
   
valueAnimator = ValueAnimator.ofInt(0, 360);valueAnimator.setDuration(mCountDownTime);valueAnimator.setInterpolator(new LinearInterpolator());valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {    @Override    public void onAnimationUpdate(ValueAnimator valueAnimator) {        progress = (int) valueAnimator.getAnimatedValue();        invalidate();    }})