常见app欢迎页圆形进度条倒计时功能,可设置显示文字,进度条颜色,宽度,倒计时时间,内圆颜色、设置进度条类型  顺数进度条(0-100)还是倒数进度条(100-0);

先上效果图:

下面介绍实现逻辑:

自定义CircleProgressbar继承TextView,在onDraw()方法里获取view边界,先画一个内部实心圆,然后画一个圆边框,然后接着在圆的中心位置画字(你要显示的字 跳转),然接开始画我们最需要的进度条了。现在画完了,那么如何显示进度条呢,我们通过Runnable 每隔 (倒计时时间秒 / 100)获取进度progress大小,通过invalidate()刷新幕实现圆形倒计时;

附上自定义view代码:public class CircleProgressbar extends TextView {

//外部轮廓的颜色

private int outLineColor = Color.BLACK;

//外部轮廓的宽度

private int outLineWidth = 2;

//内部圆的颜色

private ColorStateList inCircleColors = ColorStateList.valueOf(Color.TRANSPARENT);

//中心圆的颜色

private int circleColor;

//进度条的颜色

private int progressLineColor = Color.BLUE;

//进度条的宽度

private int progressLineWidth = 8;

//画笔

private Paint mPaint = new Paint();

//进度条的矩形区域

private RectF mArcRect = new RectF();

//进度

private int progress = 100;

//进度条类型

private ProgressType mProgressType = ProgressType.COUNT_BACK;

//进度倒计时时间

private long timeMillis = 3000;

//View的显示区域。

final Rect bounds = new Rect();

//进度条通知。

private OnCountdownProgressListener mCountdownProgressListener;

private int listenerWhat = 0;

public CircleProgressbar(Context context) {

this(context, null);

}

public CircleProgressbar(Context context, AttributeSet attrs) {

this(context, attrs, 0);

}

public CircleProgressbar(Context context, AttributeSet attrs, int defStyleAttr) {

super(context, attrs, defStyleAttr);

initialize(context, attrs);

}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)

public CircleProgressbar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {

super(context, attrs, defStyleAttr, defStyleRes);

initialize(context, attrs);

}

private void initialize(Context context, AttributeSet attributeSet) {

mPaint.setAntiAlias(true);

TypedArray typedArray = context.obtainStyledAttributes(attributeSet, R.styleable.CircleProgressbar);

if (typedArray.hasValue(R.styleable.CircleProgressbar_in_circle_color))

inCircleColors = typedArray.getColorStateList(R.styleable.CircleProgressbar_in_circle_color);

else

inCircleColors = ColorStateList.valueOf(Color.TRANSPARENT);

circleColor = inCircleColors.getColorForState(getDrawableState(), Color.TRANSPARENT);

typedArray.recycle();

}

/**

* 设置外部轮廓圆的颜色

*/

public void setOutLineColor(@ColorInt int outLineColor) {

this.outLineColor = outLineColor;

invalidate();

}

/**

* 设置外部轮廓圆的宽度

*/

public void setOutLineWidth(@ColorInt int outLineWidth) {

this.outLineWidth = outLineWidth;

invalidate();

}

/**

* 设置中心圆的颜色

*/

public void setInCircleColor(@ColorInt int inCircleColor) {

this.inCircleColors = ColorStateList.valueOf(inCircleColor);

invalidate();

}

private void validateCircleColor() {

int circleColorTemp = inCircleColors.getColorForState(getDrawableState(), Color.TRANSPARENT);

if (circleColor != circleColorTemp) {

circleColor = circleColorTemp;

invalidate();

}

}

/**

* 设置圆形进度条颜色

*/

public void setProgressColor(@ColorInt int progressLineColor) {

this.progressLineColor = progressLineColor;

invalidate();

}

/**

* 设置圆形进度条宽度

*/

public void setProgressLineWidth(int progressLineWidth) {

this.progressLineWidth = progressLineWidth;

invalidate();

}

/**

* 设置进度条值

*/

public void setProgress(int progress) {

this.progress = validateProgress(progress);

invalidate();

}

private int validateProgress(int progress) {

if (progress > 100)

progress = 100;

else if (progress < 0)

progress = 0;

return progress;

}

/**

* 获取进度值

*/

public int getProgress() {

return progress;

}

/**

* 设置倒计时时间

*/

public void setTimeMillis(long timeMillis) {

this.timeMillis = timeMillis;

invalidate();

}

/**

* 获取倒计时时间

*/

public long getTimeMillis() {

return this.timeMillis;

}

/**

* 设置进度条类型 是0-100 还是100_0

*/

public void setProgressType(ProgressType progressType) {

this.mProgressType = progressType;

resetProgress();

invalidate();

}

private void resetProgress() {

switch (mProgressType) {

case COUNT:

progress = 0;

break;

case COUNT_BACK:

progress = 100;

break;

}

}

/**

* 获取进度条类型

*/

public ProgressType getProgressType() {

return mProgressType;

}

/**

* 设置进度监听

*/

public void setCountdownProgressListener(int what, OnCountdownProgressListener mCountdownProgressListener) {

this.listenerWhat = what;

this.mCountdownProgressListener = mCountdownProgressListener;

}

public void start() {

stop();

post(progressChangeTask);

}

/**

* 开始旋转倒计时

*/

public void reStart() {

resetProgress();

start();

}

public void stop() {

removeCallbacks(progressChangeTask);

}

@Override

protected void onDraw(Canvas canvas) {

//获取view的边界

getDrawingRect(bounds);

int size = bounds.height() > bounds.width() ? bounds.width() : bounds.height();

float outerRadius = size / 2;

//画内部背景

int circleColor = inCircleColors.getColorForState(getDrawableState(), 0);

mPaint.setStyle(Paint.Style.FILL);

mPaint.setColor(circleColor);

canvas.drawCircle(bounds.centerX(), bounds.centerY(), outerRadius - outLineWidth, mPaint);

//画边框圆

mPaint.setStyle(Paint.Style.STROKE);

mPaint.setStrokeWidth(outLineWidth);

mPaint.setColor(outLineColor);

canvas.drawCircle(bounds.centerX(), bounds.centerY(), outerRadius - outLineWidth / 2, mPaint);

//画字

Paint paint = getPaint();

paint.setColor(getCurrentTextColor());

paint.setAntiAlias(true);

paint.setTextAlign(Paint.Align.CENTER);

float textY = bounds.centerY() - (paint.descent() + paint.ascent()) / 2;

canvas.drawText(getText().toString(), bounds.centerX(), textY, paint);

//画进度条

mPaint.setColor(progressLineColor);

mPaint.setStyle(Paint.Style.STROKE);

mPaint.setStrokeWidth(progressLineWidth);

// mPaint.setStrokeCap(Paint.Cap.ROUND);

mPaint.setAntiAlias(true);

int deleteWidth = progressLineWidth + outLineWidth;

mArcRect.set(bounds.left + deleteWidth / 2, bounds.top + deleteWidth / 2, bounds.right - deleteWidth / 2, bounds.bottom - deleteWidth / 2);

canvas.drawArc(mArcRect, -90, -360 * progress / 100, false, mPaint);

}

@Override

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

super.onMeasure(widthMeasureSpec, heightMeasureSpec);

int lineWidth = 4 * (outLineWidth + progressLineWidth);

int width = getMeasuredWidth();

int height = getMeasuredHeight();

int size = (width > height ? width : height) + lineWidth;

setMeasuredDimension(size, size);

}

@Override

protected void drawableStateChanged() {

super.drawableStateChanged();

validateCircleColor();

}

private Runnable progressChangeTask = new Runnable() {

@Override

public void run() {

removeCallbacks(this);

switch (mProgressType) {

//判断是顺数进度条还是倒数进度条

case COUNT:

progress += 1;

break;

case COUNT_BACK:

progress -= 1;

break;

}

if (progress >= 0 && progress <= 100) {

if (mCountdownProgressListener != null)

mCountdownProgressListener.onProgress(listenerWhat, progress);

invalidate();

postDelayed(progressChangeTask, timeMillis / 100);

} else

progress = validateProgress(progress);

}

};

public enum ProgressType {

/**

* 顺数进度条,从0-100;

*/

COUNT,

/**

* 倒数进度条,从100-0;

*/

COUNT_BACK;

}

public interface OnCountdownProgressListener {

void onProgress(int what, int progress);

}

}

在java代码中设置你所需要的样式、 时间等;

注意:

在布局文件中需要在自定义布局外包裹一层 LinearLayout ,防止通过Arcrect画最外层的进度条成椭圆问题;

xml布局代码:

android:layout_width="wrap_content"

android:layout_height="wrap_content">

android:id="@+id/tv_red_skip"

android:layout_width="30dp"

android:text="跳过"

android:textColor="#ffffff"

android:textSize="10sp"

android:layout_height="30dp" />

下面附上demo下载地址:

https://download..net/download/shanshan_1117/10299524

点击打开链接

android欢迎页圆形倒计时,android 欢迎页圆形进度条倒计时功能相关推荐

  1. html圆圈倒计时,html5 css3圆形进度条倒计时页面跳转代码

    特效描述:html5 css3 圆形进度条 倒计时 页面跳转代码.html5 css3进度条倒计时动画特效 代码结构 1. HTML代码 html5+css3进度条倒计时动画特效 body { mar ...

  2. h5动画 php,HTML_多视角3D逼真HTML5水波动画 ,html5+css3进度条倒计时动画特效 - phpStudy...

    多视角3D逼真HTML5水波动画 html5+css3进度条倒计时动画特效这个作品在今天上网找网络资源的时候无意中发现的,看到效果非常棒并且很实用,就第一时间把它整理出来与大家分享了,主要用到了htm ...

  3. html5倒计时效果,html5+css3进度条倒计时动画特效代码【推荐】

    html5+css3进度条倒计时动画特效这个作品在今天上网找网络资源的时候无意中发现的,看到效果非常棒并且很实用,就第一时间把它整理出来与大家分享了,主要用到了html5.javascript和css ...

  4. html进度条倒计时代码,html5+css3进度条倒计时动画特效代码【推荐】_html5教程技巧...

    html5+css3进度条倒计时动画特效这个作品在今天上网找网络资源的时候无意中发现的,看到效果非常棒并且很实用,就第一时间把它整理出来与大家分享了,主要用到了html5.javascript和css ...

  5. Android小项目之--前台界面与用户交互的对接 进度条与拖动条(附源码)

    都知道水果公司(苹果)是己尊重用户体验著称的公司,其设计的产品人性化十足,不得不令后来者赞叹,竞相模仿.iphone的成功就是其典型的案例,做为其移动系统的死对头 Google 想要在市场上分得一杯羹 ...

  6. Android 自定义View实现环形带刻度颜色渐变的进度条

    上次写了一篇Android 自定义View实现环形带刻度的进度条,这篇文章就简单了,只是在原来的基础上加一个颜色渐变. 按照惯例,我们先来看看效果图 一.概述 1.相比于上篇文章,这里我们的颜色渐变主 ...

  7. [Android]webview直接加载网页允许JS,进度条,当前应用内跳转

    webview,用于在应用里面直接加载网页 本代码参考了: 官方的webview实例介绍:https://developer.android.com/guide/tutorials/views/hel ...

  8. android显示服务器端文件夹,Android上传文件到服务端并显示进度条

    最近在做上传文件的服务,简单看了网上的教程.结合实践共享出代码. 由于网上的大多数没有服务端的代码,这可不行呀,没服务端怎么调试呢. Ok,先上代码. Android 上传比较简单,主要用到的是 Ht ...

  9. android 自定义view 加载图片,Android自定义View基础开发之图片加载进度条

    学会了Paint,Canvas的基本用法之后,我们就可以动手开始实践了,先写个简单的图片加载进度条看看. 按照惯例,先看效果图,再决定要不要往下看: 既然看到这里了,应该是想了解这个图片加载进度条了, ...

最新文章

  1. 从GitHub上无法下载子模块问题解决
  2. 前端开发这么多年,你真的了解浏览器页面渲染机制吗?
  3. matlab拟合函数,Matlab拟合自定义函数 - 计算模拟 - 小木虫 - 学术 科研 互动社区...
  4. 求最大、次大和第3大的值
  5. MapTask、ReduceTask并行度决定机制
  6. android开启热点softap模式,[RK3288][Android6.0] Wifi开启热点(SoftAP)流程小结
  7. 【clickhouse】clickhouse UTC 时间带有时区 如何写入
  8. asp与php对比,ASP和PHP文件操作速度的对比
  9. 2014蓝桥杯:李白打酒;奇怪的分式(枚举,最大公约数)
  10. VCL从RES中读取皮肤
  11. 【生活相关】二(2014年新年畅想)
  12. 利用Python下载文件
  13. 数据结构题集(C语言版)——第一张 绪论(1~6)
  14. 逆天了!全地形、四舵轮、八连杆、独立悬挂的机器人运动结构方案,来了!
  15. 神经网络、结构、权重和矩阵
  16. 西北乱跑娃 --- requests爬虫五大反反爬机制
  17. Power BI-销售业绩分析展示
  18. 公司股权分配方案 (2)
  19. 为什么手机里的小爱音响app里搜不到家里的小爱音箱_平板+智能音箱=小爱触屏音响Pro8...
  20. 杜洋单片机c语言,杜洋工作室 DoYoung Studio

热门文章

  1. AlgorithmMan,一套免费的算法演示神器(开源动画演示版)
  2. jquery 图像滑块_如何使用jQuery构建图像滑块
  3. 原型制作是什么意思_制作电路原型的最佳方法是什么?
  4. javascript测试_了解有关JavaScript承诺的更多信息:25次测试中从零到英雄
  5. Swift中的函数curring简介
  6. php kibana查询,搜索您的数据 | Kibana 用户手册 | Elastic
  7. python数码时钟代码_python实现简易数码时钟
  8. 力扣-复制带随机指针的链表
  9. Python实现进度条和时间预估的示例代码
  10. 关于TCP协议的大部分,面试常问的几点都在这理里了