当前位置:网站首页>Triple half circle progress bar, you can use it directly
Triple half circle progress bar, you can use it directly
2022-07-07 04:02:00 【Super hard Golden Toad mushroom】
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
public class HalfCircleView extends View {
private int maxProgress = 100;
private float progress = 30f;
private float progress2 = 30f;
private float progress3 = 30f;
private int circleLineStrokeWidth = 50; // The width of the arc
private final int txtStrokeWidth = 3;
// The distance area where the circle is drawn ,RecF Represents a rectangular area , A rectangular area corresponds to an ellipse , Accuracy of Float,RECT Accuracy of Int
private final RectF progressRectF;
private final Paint progressPaint;
private final RectF progressRectF2;
private final Paint progressPaint2;
private final RectF progressRectF3;
private final Paint progressPaint3;
public HalfCircleView(Context context, AttributeSet attrs) {
super(context, attrs);
progressRectF = new RectF();
progressPaint = new Paint();
progressRectF2 = new RectF();
progressPaint2 = new Paint();
progressRectF3 = new RectF();
progressPaint3 = new Paint();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int radius = getRadius();
drawBackgroundRecf(radius);
drawProgress(canvas);
// Draw progress percentage display
// drawText(canvas, radius);
}
private void drawBackgroundRecf(int radius) {
// Location
progressRectF.left = circleLineStrokeWidth / 2;
progressRectF.top = circleLineStrokeWidth / 2;
progressRectF.right = radius - circleLineStrokeWidth / 2;
progressRectF.bottom = radius - circleLineStrokeWidth / 2;
progressRectF2.left = circleLineStrokeWidth * 4;
progressRectF2.top = circleLineStrokeWidth * 4;
progressRectF2.right = radius - circleLineStrokeWidth * 4;
progressRectF2.bottom = radius - circleLineStrokeWidth * 4;
progressRectF3.left = circleLineStrokeWidth * 8;
progressRectF3.top = circleLineStrokeWidth * 8;
progressRectF3.right = radius - circleLineStrokeWidth * 8;
progressRectF3.bottom = radius - circleLineStrokeWidth * 8;
}
private int getRadius() {
int width = this.getWidth() - circleLineStrokeWidth * 2;
// Because what you want to draw is a semicircle , The semicircle must be in a rectangle
// When drawing a semicircle, you are actually drawing a part of a whole circle in a square
// Then the radius of our whole circle is the width of the half circle progress bar
return width;
}
private void drawProgress(Canvas canvas) {
canvas.drawColor(Color.TRANSPARENT); // Canvas Color
progressPaint.setAntiAlias(true); // Set whether anti aliasing
progressPaint.setColor(Color.rgb(0xe9, 0xe9, 0xe9));
progressPaint.setStrokeWidth(circleLineStrokeWidth); // Set border width
progressPaint.setStyle(Paint.Style.STROKE); //stroke Means interrupt does not fill , Ring
canvas.drawArc(progressRectF, 180, 180, false, progressPaint); // startAngel Represents the starting angle of the arc ,sweepAngle Represents the angle of the arc ( span ), useCenter Indicates whether the center is included , Draw as a fan !
if (progress > 80) {
progressPaint.setColor(Color.rgb(34,219,126)); // Greater than 80 Then the progress bar is green
} else {
progressPaint.setColor(Color.rgb(247, 169, 45)); // Less than 80 And it can reveal which lines of code may need further testing
}
canvas.drawArc(progressRectF, 180, (progress / maxProgress) * 180, false, progressPaint);
progressPaint2.setAntiAlias(true); // Set whether anti aliasing
progressPaint2.setColor(Color.rgb(0xe9, 0xe9, 0xe9));
progressPaint2.setStrokeWidth(circleLineStrokeWidth); // Set border width
progressPaint2.setStyle(Paint.Style.STROKE); //stroke Means interrupt does not fill , Ring
canvas.drawArc(progressRectF2, 180, 180, false, progressPaint2); // startAngel Represents the starting angle of the arc ,sweepAngle Represents the angle of the arc ( span ), useCenter Indicates whether the center is included , Draw as a fan !
if (progress2 > 80) {
progressPaint2.setColor(Color.rgb(34,219,126)); // Greater than 80 Then the progress bar is green
} else {
progressPaint2.setColor(Color.rgb(247, 169, 45)); // Less than 80 And it can reveal which lines of code may need further testing
}
canvas.drawArc(progressRectF2, 180, (progress2 / maxProgress) * 180, false, progressPaint2);
progressPaint3.setAntiAlias(true); // Set whether anti aliasing
progressPaint3.setColor(Color.rgb(0xe9, 0xe9, 0xe9));
progressPaint3.setStrokeWidth(circleLineStrokeWidth); // Set border width
progressPaint3.setStyle(Paint.Style.STROKE); //stroke Means interrupt does not fill , Ring
canvas.drawArc(progressRectF3, 180, 180, false, progressPaint3); // startAngel Represents the starting angle of the arc ,sweepAngle Represents the angle of the arc ( span ), useCenter Indicates whether the center is included , Draw as a fan !
if (progress3 > 80) {
progressPaint3.setColor(Color.rgb(34,219,126)); // Greater than 80 Then the progress bar is green
} else {
progressPaint3.setColor(Color.rgb(247, 169, 45)); // Less than 80 And it can reveal which lines of code may need further testing
}
canvas.drawArc(progressRectF3, 180, (progress3 / maxProgress) * 180, false, progressPaint3);
}
private void drawText(Canvas canvas, int radius) {
progressPaint.setStrokeWidth(txtStrokeWidth);
String progressText = progress + "%";
progressPaint.setTextSize(radius / 4);
int textWidth = (int) progressPaint.measureText(progressText, 0, progressText.length());
progressPaint.setStyle(Paint.Style.FILL);
canvas.drawText(progressText, radius / 2 - textWidth / 2, radius / 2, progressPaint);
}
public void setProgress(float progress, float progress2, float progress3) {
this.progress = progress;
this.progress2 = progress2;
this.progress3 = progress3;
this.invalidate();
}
public void setProgressNotInUiThread(float progress) {
this.progress = progress;
this.postInvalidate();
}
public void setCircleLineStrokeWidth(int circleLineStrokeWidth) {
this.circleLineStrokeWidth = circleLineStrokeWidth;
this.invalidate();
}
}
边栏推荐
- 中青杯2022A题高校数学建模竞赛与课程教育思路分析
- Collection of idea gradle Lombok errors
- Termux set up the computer to connect to the mobile phone. (knock the command quickly), mobile phone termux port 8022
- MySQL的索引
- ABAP dynamic inner table grouping cycle
- golang 压缩和解压zip文件
- Construction of Hisilicon universal platform: color space conversion YUV2RGB
- VHDL implementation of single cycle CPU design
- 手机号国际区号JSON格式另附PHP获取
- 概率论公式
猜你喜欢

Baidu map JS development, open a blank, bmapgl is not defined, err_ FILE_ NOT_ FOUND

Storage of data

Summer 2022 daily question 1 (1)

Web service performance monitoring scheme

Hisilicon 3559 universal platform construction: RTSP real-time playback support

卡尔曼滤波-1

Construction of Hisilicon universal platform: color space conversion YUV2RGB

一些常用软件相关

力扣------路径总和 III

leetcode:面试题 17.24. 子矩阵最大累加和(待研究)
随机推荐
QT 使用QToolTip 鼠标放上去显示文字时会把按钮的图片也显示了、修改提示文字样式
[leetcode] 700 and 701 (search and insert of binary search tree)
Delete data in SQL
Tflite model transformation and quantification
SSL certificate deployment
【系统管理】清理任务栏的已删除程序的图标缓存
使用 TiDB Lightning 恢复 GCS 上的备份数据
ABAP Dynamic Inner table Group cycle
QT thread and other 01 concepts
如何编写一个程序猿另一个面试官眼前一亮的简历[通俗易懂]
Some thoughts on cross end development of kbone and applet
Index of MySQL
Quick completion guide of manipulator (10): accessible workspace
AVL树插入操作与验证操作的简单实现
1.19.11.SQL客户端、启动SQL客户端、执行SQL查询、环境配置文件、重启策略、自定义函数(User-defined Functions)、构造函数参数
First understand the principle of network
List interview common questions
Enter the rough outline of the URL question (continuously updated)
你心目中的数据分析 Top 1 选 Pandas 还是选 SQL?
红米k40s root玩机笔记