Вот чего я пытаюсь достичь:

Вот моя текущая реализация:< /p>
Код: Выделить всё
@Composable
fun StepsProgressView(
steps: List,
modifier: Modifier = Modifier,
lineWidth: Dp = 1.dp,
completedIndex: Int = 2
) {
Column(modifier = modifier) {
Box(contentAlignment = Alignment.Center) {
Canvas(modifier = Modifier.fillMaxWidth()) {
val width = drawContext.size.width
val height = drawContext.size.height
val yOffset = height / 2
val itemWidth = width / steps.size
var startOffset = itemWidth / 2
var endOffset = startOffset
val barWidth = lineWidth.toPx()
repeat(steps.size - 1) { index ->
endOffset += itemWidth
drawLine(
brush = SolidColor(if (index < completedIndex) primaryColor else grayDividerColor),
start = Offset(startOffset, yOffset),
end = Offset(endOffset, yOffset),
strokeWidth = barWidth
)
startOffset = endOffset
}
}
Row(
Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceAround,
verticalAlignment = Alignment.CenterVertically,
) {
repeat(steps.size) { index ->
Box(contentAlignment = Alignment.Center) {
// last index image
if (index == steps.lastIndex)
Image(
painter = painterResource(id = R.drawable.barImage),
contentDescription = null,
modifier = Modifier.size(24.dp),
contentScale = ContentScale.Crop
)
// circles box
else
Box(
modifier = Modifier
.size(12.dp)
.drawBehind {
drawCircle(
color =
if (index
HelpText(
text = step.title,
fontSize = 13,
modifier = Modifier.wrapContentWidth().weight(1f),
color = if (steps.indexOf(step)
Подробнее здесь: [url]https://stackoverflow.com/questions/78735635/how-to-center-text-views-in-a-custom-progress-bar-in-jetpack-compose[/url]
Мобильная версия