CircularProgressIndicator:无法正确调整大小

huangapple go评论90阅读模式
英文:

CircularProgressIndicator: Can't resize properly

问题

我的代码:

Row (
    modifier = Modifier.fillMaxWidth().padding(16.dp),
    verticalAlignment = Alignment.CenterVertically
) {
    Checkbox(
        checked = checked,
        enabled = habit.enabled,
        onCheckedChange = { checked = !checked },
        modifier = Modifier.size(23.dp).padding(end = 8.dp)
    )
    CircularProgressIndicator(
        progress = animatedProgress,
        modifier = Modifier.size(23.dp).padding(end = 8.dp)
    )
    Icon(
        imageVector = habit.icon,
        contentDescription = null,
        modifier = Modifier.padding(end = 8.dp)
    )
    Text(
        text = LocalContext.current.getString(habit.stringResourceId),
        maxLines = 1
    )
}

这是它的输出:

CircularProgressIndicator:无法正确调整大小

我希望它与复选框和图标的大小相同,但由于某种原因它没有达到这个效果。

英文:

My code:

Row (
    modifier = Modifier.fillMaxWidth().padding(16.dp),
    verticalAlignment = Alignment.CenterVertically
) {
    Checkbox(
        checked = checked,
        enabled = habit.enabled,
        onCheckedChange = { checked = !checked },
        modifier = Modifier.size(23.dp).padding(end = 8.dp)
    )
    CircularProgressIndicator(
        progress = animatedProgress,
        modifier = Modifier.size(23.dp).padding(end = 8.dp)
    )
    Icon(
        imageVector = habit.icon,
        contentDescription = null,
        modifier = Modifier.padding(end = 8.dp)
    )
    Text(
        text = LocalContext.current.getString(habit.stringResourceId),
        maxLines = 1
    )
}

Here's what it outputs:

CircularProgressIndicator:无法正确调整大小

I want it to be the same size as checkbox and icon, but it does that for some reason.

答案1

得分: 1

请注意,我将为您提供代码的翻译,但是我无法显示图片。以下是您提供的代码的翻译:

将Row的每个项目使用Box布局包装,使用以下代码片段。

@Preview(showBackground = true)
@Composable
fun Test() {
    Row(
        modifier = Modifier
            .fillMaxWidth()
            .padding(16.dp),
        verticalAlignment = Alignment.CenterVertically
    ) {
        val modifier = Modifier
            .padding(end = 8.dp)
        Box(
            modifier = modifier,
        ) {
            Checkbox(
                checked = true,
                enabled = true,
                onCheckedChange = {},
                modifier = Modifier.size(23.dp)
            )
        }

        Box(
            modifier = modifier,
        ) {
            CircularProgressIndicator(
                progress = 0.9f,
                strokeWidth = 2.dp,
                modifier = Modifier.size(23.dp)
            )
        }

        Box(
            modifier = modifier,
        ) {
            Icon(
                imageVector = Icons.Default.Info,
                contentDescription = null,
                modifier = Modifier
                    .size(23.dp)
            )
        }

        Text(
            text = "Some Text Goes Here",
            maxLines = 1
        )
    }
}

上述代码片段将产生以下结果。

CircularProgressIndicator:无法正确调整大小

英文:

Wrap each item of Row with Box layout, Use below code snippet.

@Preview(showBackground = true)
@Composable
fun Test() {
Row(
    modifier = Modifier
        .fillMaxWidth()
        .padding(16.dp),
    verticalAlignment = Alignment.CenterVertically
) {
    val modifier = Modifier
        .padding(end = 8.dp)
    Box(
        modifier = modifier,
    ) {
        Checkbox(
            checked = true,
            enabled = true,
            onCheckedChange = {},
            modifier = Modifier.size(23.dp)
        )
    }

    Box(
        modifier = modifier,
    ) {
        CircularProgressIndicator(
            progress = 0.9f,
            strokeWidth = 2.dp,
            modifier = Modifier.size(23.dp)
        )
    }

    Box(
        modifier = modifier,
    ) {
        Icon(
            imageVector = Icons.Default.Info,
            contentDescription = null,
            modifier = Modifier
                .size(23.dp)
        )
    }

    Text(
        text = "Some Text Goes Here",
        maxLines = 1
    )
  }
}

This above code snippet will yield result like this.

CircularProgressIndicator:无法正确调整大小

huangapple
  • 本文由 发表于 2023年8月9日 11:24:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76864361.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定