当前位置:网站首页>Compose canvas custom circular progress bar
Compose canvas custom circular progress bar
2022-07-26 07:16:00 【Ango can't move】
@Composable
fun CircleRing(boxWidthDp: Int, viewModel: TaskViewModel) {
Canvas(modifier = Modifier.size(boxWidthDp.dp), onDraw = {
val strokWidth = 30F
// Grey background
drawArc(
Color(0, 0, 0, 15),
startAngle = 160f,
sweepAngle = 220f,
useCenter = false,
style = Stroke(strokWidth, cap = StrokeCap.Round),
)
drawArc(
Color.White,
startAngle = 160f,
sweepAngle = viewModel.pointOfYearPercent,
useCenter = false,
style = Stroke(strokWidth, cap = StrokeCap.Round),
)
})
}
The progress is self-contained
// Academic year points
var pointOfYear by mutableStateOf(10000)
private set
// Progress of academic year points 220f * pointOfYear / Total academic year points
var pointOfYearPercent by mutableStateOf(0f)
private set
/**
* Update learning progress
*/
fun updatePointPercent() {
pointOfYearPercent = 220f * pointOfYear / totalPointOfYear
}
effect

The whole content data is as follows
Box(contentAlignment = Alignment.Center,
modifier = Modifier
.height(boxWidthDp.dp)
.padding(top = 16.dp)
) {
// ring
CircleRing(boxWidthDp = boxWidthDp, taskViewModel)
// Progress data
Column(modifier = Modifier
.align(Alignment.Center)
.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally) {
Text(buildAnnotatedString {
append(taskViewModel.pointOfYear.toString())
withStyle(SpanStyle(fontSize = 10.sp)) {
append(" branch ")
}
},
fontSize = 36.sp,
color = Color.White)
Text(text = " Academic year points ", fontSize = 12.sp,
color = Color.White)
}
}Remember to shift it upward in the next component 40dp Otherwise, there is too much space

边栏推荐
- HCIP --- MPLS技术
- File server fastdfs
- QT: modal, modeless, text box, button, single line input box
- Deep learning visualization
- 【C语言】你真的了解printf吗?(printf典型易错,强烈建议收藏)
- With Huawei cloud welink, you can connect to the world even in the countryside
- 数据平台调度升级改造 | 从Azkaban 平滑过度到 Apache DolphinScheduler 的操作实践
- IDEA——使用@Slf4j打印日志
- 20220725 自动控制原理中的补偿器
- Redis migrate tool migration error.
猜你喜欢

C51 and MDK coexist keil5 installation tutorial

20220725 compensator in automatic control principle

Drools(4):Drools基础语法(2)

No .egg-info directory found in xxx\pip-pip-egg-info-mq

Apache DolphinScheduler&TiDB联合Meetup | 聚焦开源生态发展下的应用开发能力

Acwing- daily question

A guide for you to fully use TS

Differences in the use of function call pointer parameters *p, * & P

中国联通改造 Apache DolphinScheduler 资源中心,实现计费环境跨集群调用与数据脚本一站式访问

C51与MDK共存 Keil5安装教程
随机推荐
Drools(3):Drools基础语法(1)
20220725 convolution in automatic control principle
Moonbeam orbiters program: provides a new way for collectors to participate in moonbeam and Moonriver
替换license是否要重启数据库?
With Huawei cloud welink, you can connect to the world even in the countryside
【QT】怎样获得QTableView和QTableWidget的行数和列数
LTS(Light-Task-Scheduler)
Summer Challenge harmonyos - hamster game based on arkui (JS)
如何对C盘进行扩容重新分区?
配置Flask
Redis migrate tool migration error.
Orthogonality of 20220724 trigonometric function system
Qt:列表框、表格、树形控件
Become an Apache contributor, so easy!
达人专栏 | 还不会用 Apache Dolphinscheduler?大佬用时一个月写出的最全入门教程【三】
Learn browser decoding from XSS payload
Idea -- use @slf4j to print logs
Embedded development: tools -- intelligent watchdog design
屏:框贴、0贴合、全贴合
Check the top 10 best graphics software of the year, meet 99% of your chart needs, and collect it quickly