package com.ecaray.semicircleprogressbar;
import android.animation.Animator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathMeasure;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.graphics.SweepGradient;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
/**
* 类描述:自定义半圆形进度条
* 创建人: Beibaoke.Kongming
* 创建时间: 2018/1/8 11:49
* 修改人: Beibaoke.Kongming
* 修改时间: 2018/1/8 11:49
*/
public class SemicircleProgressBar extends View {
private Paint paint;//画笔
private Paint shaderPaint;//彩色画笔
private Paint bitmapPaint;//图片画笔
private Paint textPaint;//文字画笔
/**
* 控件宽度
*/
private int width;
/**
* 控件高度
*/
private int height;
/**
* 半径
*/
private int radius;
/**
* 外圆弧的宽度
*/
private float outerArcWidth;
/**
* 内部大圆弧的宽度
*/
private float insideArcWidth;
/**
* 两圆弧中间间隔距离
*/
private float spaceWidth;
/**
* 两圆弧中间间隔距离
*/
private float percentTextSize;
/**
* 最外层滑动小球的半径
*/
private float scrollCircleRadius;
/**
* 粉红底色
*/
private int pinkColor;
/**
* 黄色
*/
private int yellowColor;
/**
* 粉色红
*/
private int pinkRedColor;
/**
* 浅红
*/
private int redColor;
/**
* 深红
*/
private int deepRedColor;
/**
* 灰色
*/
private int grayColor;
/**
* 间隔的角度
*/
private double spaceAngle = 22.5;
/**
* 两条圆弧的起始角度
* 起始角度控制半圆开口的大小,数值越小开口越大,数值越大开口越小
*/
private double floatAngel = 50;
/**
* 自定义的Bitmap
*/
private Bitmap mBitmap;
/**
* 自定义的画布,目的是为了能画出重叠的效果
*/
private Canvas mCanvas;
/**
* 时刻变化的Angel
*/
private double mAngel;
/**
* 内弧半径
*/
private float insideArcRadius;
private double aimPercent = 0;
private float[] pos; // 当前点的实际位置
private float[] tan; // 当前点的tangent值,用于计算图片所需旋转的角度
private Bitmap mBitmapBackDeepRed; // 箭头图片
private Bitmap mBitmapBackYellow; // 箭头图片
private Bitmap mBitmapBackPink; // 箭头图片
private Bitmap mBitmapBackRed; // 箭头图片
private Matrix mMatrix; // 矩阵,用于对图片进行一些操作
private RectF insideArea; //内圆的矩形
private Bitmap mBitmapBack;
// 动效过程监听器
private ValueAnimator.AnimatorUpdateListener mUpdateListener;
private Animator.AnimatorListener mAnimatorListener;
//过程动画
private ValueAnimator mValueAnimator;
// 用于控制动画状态转换
private Handler mAnimatorHandler;
// 默认的动效周期 2s
private int defaultDuration = 0;
public SemicircleProgressBar(Context context) {
super(context);
initView(context);
}
public SemicircleProgressBar(Context context, AttributeSet attrs) {
super(context, attrs);
initView(context);
}
public SemicircleProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initView(context);
}
private void initView(Context context) {
shaderPaint = new Paint();
textPaint = new Paint();
paint = new Paint();
paint.setStyle(Paint.Style.STROKE); //设置空心
paint.setAntiAlias(true);
paint.setColor(Color.RED);
bitmapPaint = new Paint();
bitmapPaint.setStyle(Paint.Style.FILL);
bitmapPaint.setAntiAlias(true);
outerArcWidth = context.getResources().getDimensionPixelOffset(R.dimen.dp2);
insideArcWidth = context.getResources().getDimensionPixelOffset(R.dimen.dp12);
spaceWidth = context.getResources().getDimensionPixelOffset(R.dimen.dp12);
scrollCircleRadius = context.getResources().getDimensionPixelOffset(R.dimen.dp4);
percentTextSize = context.getResources().getDimensionPixelOffset(R.dimen.dp8);
pinkColor = context.getResources().getColor(R.color.glay3);
yellowColor = context.getResources().getColor(R.color.timeCome2);
pinkRedColor = context.getResources().getColor(R.color.timeCome1);
redColor = context.getResources().getColor(R.color.timeCome1);
deepRedColor = context.getResources().getColor(R.color.timeCome1);
grayColor = context.getResources().getColor(R.color.glay3);
pos = new float[2];
tan = new float[2];
mBitmapBackDeepRed = BitmapFactory.decodeResource(context.getResources(), R.mipmap.order_dot);
mBitmapBackRed = BitmapFactory.decodeResource(context.getResources(), R.mipmap.order_dot);
mBitmapBackPink = BitmapFactory.decodeResource(context.getResources(), R.mipmap.order_dot);
mBitmapBackYellow = BitmapFactory.decodeResource(context.getResources(), R.mipmap.order_dot);
mMatrix = new Matrix();
}
private int count = 0;
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Log.i("PercentVIew", "开始绘制" + count);
long startTime = System.currentTimeMillis();
count++;
width = getWidth(); //获取宽度
height = getHeight();//获取高度
mBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
mCanvas = new Canvas(mBitmap);
radius = height / 2;
insideArcRadius = radius - scrollCircleRadius - spaceWidth;//内弧半径
// Log.i(TAG,"最外园半径"+radius+"\n高度为"+height);
// Log.i(TAG,"最外园半径"+Math.sin(Math.toRadians(spaceAngle)));
paintPercentBack(mCanvas);
paintPercent(mAngel, aimPercent, mCanvas);
canvas.drawBitmap(mBitmap, 0, 0, null);
long endTime = System.currentTimeMillis();
Log.i("PercentVIew", "绘制结束" + (endTime - startTime));
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
/**
* 画线的底色
*/
private void paintPercentBack(Canvas canvas) {
paint.setColor(grayColor);
paint.setStrokeWidth(outerArcWidth);//outerArcWidth
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeCap(Paint.Cap.ROUND);//设置为圆角
paint.setAntiAlias(true);
//绘制里层大宽度弧形底色
paint.setColor(pinkColor);
paint.setStrokeWidth(insideArcWidth);
paint.setStyle(Paint.Style.STROKE);
canvas.drawArc(new RectF(width / 2 - insideArcRadius, radius - insideArcRadius, width / 2 + insideArcRadius, radius + insideArcRadius),
(float) (180 - floatAngel),
(float) (180 + 2 * floatAngel), false, paint);
}
/***
* 4个色值由浅到深分别是 ffd200 ff5656 fa4040 f60157
* 等级划分:0-20
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Android自定义半圆进度条 (203个子文件)
gradlew.bat 2KB
fileSnapshots.bin 2.49MB
classAnalysis.bin 928KB
taskHistory.bin 368KB
jarAnalysis.bin 314KB
fileHashes.bin 253KB
taskHistory.bin 64KB
taskJars.bin 20KB
resourceHashesCache.bin 19KB
last-build.bin 1B
built.bin 0B
.gitignore 127B
.gitignore 8B
build.gradle 965B
build.gradle 573B
settings.gradle 16B
gradlew 5KB
app.iml 11KB
SemicircleProgressBar.iml 875B
gradle-wrapper.jar 52KB
SemicircleProgressBar.java 15KB
MainActivity.java 2KB
ExampleInstrumentedTest.java 791B
ExampleUnitTest.java 426B
profile-2018-01-03-21-37-17-578.json 69KB
profile-2018-01-04-10-26-48-674.json 58KB
profile-2018-01-03-21-53-12-889.json 58KB
profile-2018-01-03-21-46-00-475.json 58KB
profile-2018-01-04-10-28-22-627.json 58KB
profile-2018-01-03-21-59-47-140.json 58KB
profile-2018-01-04-15-45-05-413.json 58KB
profile-2018-01-04-15-54-41-639.json 58KB
profile-2018-01-04-10-27-36-758.json 58KB
profile-2018-01-04-15-49-14-867.json 58KB
profile-2018-01-03-21-55-32-684.json 58KB
profile-2018-01-04-15-56-11-028.json 58KB
profile-2018-01-04-15-54-04-684.json 58KB
profile-2018-01-04-15-48-03-253.json 58KB
profile-2018-01-03-21-56-02-120.json 58KB
profile-2018-01-03-22-00-58-914.json 58KB
profile-2018-01-03-21-54-57-971.json 58KB
profile-2018-01-03-21-56-40-432.json 58KB
profile-2018-01-03-21-57-09-598.json 58KB
profile-2018-01-03-21-46-30-315.json 58KB
profile-2018-01-03-22-00-22-809.json 58KB
profile-2018-01-04-16-05-42-602.json 58KB
profile-2018-01-04-15-51-39-720.json 58KB
profile-2018-01-04-15-34-11-684.json 58KB
profile-2018-01-04-15-44-52-343.json 58KB
profile-2018-01-08-11-55-25-358.json 58KB
profile-2018-01-04-15-57-09-582.json 58KB
profile-2018-01-04-15-49-55-046.json 58KB
profile-2018-01-04-15-47-38-565.json 58KB
profile-2018-01-04-15-48-53-917.json 58KB
profile-2018-01-04-16-00-59-774.json 58KB
profile-2018-01-03-21-39-45-384.json 58KB
profile-2018-01-04-09-38-02-005.json 58KB
profile-2018-01-04-10-09-24-919.json 58KB
profile-2018-01-04-10-22-07-718.json 58KB
profile-2018-01-08-12-00-11-677.json 58KB
profile-2018-01-08-14-17-49-185.json 58KB
profile-2018-01-04-15-43-31-359.json 58KB
profile-2018-01-03-21-43-27-602.json 58KB
profile-2018-01-04-10-24-25-504.json 58KB
profile-2018-01-04-15-38-30-645.json 58KB
profile-2018-01-04-15-36-20-535.json 58KB
profile-2018-01-03-21-42-59-134.json 58KB
profile-2018-01-08-14-24-37-921.json 58KB
profile-2018-01-03-21-42-16-261.json 58KB
profile-2018-01-04-15-42-34-349.json 58KB
profile-2018-01-03-21-40-48-214.json 58KB
profile-2018-01-04-10-25-36-421.json 58KB
profile-2018-01-04-15-41-11-152.json 58KB
profile-2018-01-03-21-47-31-999.json 54KB
profile-2018-01-03-21-56-29-982.json 54KB
profile-2018-01-04-15-49-05-273.json 54KB
profile-2018-01-03-21-33-10-345.json 48KB
profile-2018-01-08-11-49-45-242.json 47KB
profile-2018-01-04-09-33-32-651.json 47KB
profile-2018-01-08-11-49-00-463.json 23KB
profile-2018-01-04-09-33-16-725.json 23KB
javaCompile.lock 17B
fileContent.lock 17B
fileHashes.lock 17B
taskHistory.lock 17B
cache.properties.lock 2B
ic_launcher_round.png 15KB
ic_launcher_round.png 10KB
ic_launcher.png 9KB
ic_launcher_round.png 7KB
ic_launcher.png 6KB
ic_launcher_round.png 5KB
ic_launcher.png 4KB
ic_launcher.png 3KB
ic_launcher_round.png 3KB
order_dot.png 3KB
ic_launcher.png 2KB
proguard-rules.pro 772B
gradle.properties 747B
local.properties 419B
共 203 条
- 1
- 2
- 3
资源评论
- zillvip2019-07-29非常不错,使用啦
- xxmv992020-12-31非常不错,使用啦
- 小李子No12019-04-05不错,还没看呢
- Godery2022-04-18抖动 不好用 还的修改
- m0_618020072023-09-13靠,浪费钱,不能用
简雨山舍
- 粉丝: 44
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功