CircularProgressIndicator: 无法正确调整大小

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

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
    )
}

希望以上翻译对您有所帮助。

英文:

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-2.html
匿名

发表评论

匿名网友

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

确定