单选对话框项目文本未与单选按钮对齐

Mac*_*ver 2 android kotlin android-jetpack-compose

由于某种原因,文本组件没有像对话框中的单选按钮那样完全垂直对齐。我尝试调整每个部分的填充值,但仍然没有任何效果。

@Composable
fun CommonDialog(
    title: String?,
    state: MutableState<Boolean>,
    content: @Composable (() -> Unit)? = null
) {
    AlertDialog(
        onDismissRequest = {
            state.value = false
        },
        title = title?.let {
            {
                Column(
                    Modifier.fillMaxWidth(),
                    verticalArrangement = Arrangement.spacedBy(5.dp)
                ) {
                    Text(text = title)
                }
            }
        },
        text = content,
        confirmButton = {
            TextButton(onClick = { state.value = false }) {
                Text(stringResource(id = R.string.button_cancel))
            }
        }, modifier = Modifier.padding(vertical = 5.dp)
    )
}

@Composable
fun AlertSingleChoiceView(state: MutableState<Boolean>) {
    CommonDialog(title = stringResource(id = R.string.theme), state = state) {
        SingleChoiceView()
    }
}

@Composable
fun SingleChoiceView() {
    val radioOptions = listOf(
        stringResource(id = R.string.straight),
        stringResource(id = R.string.curly),
        stringResource(id = R.string.wavy))
    val (selectedOption, onOptionSelected) = remember { mutableStateOf(radioOptions[2]) }
    Column(
        Modifier.fillMaxWidth()
    ) {
        radioOptions.forEach { text ->
            Row(
                Modifier
                    .fillMaxWidth()
                    .selectable(
                        selected = (text == selectedOption),
                        onClick = {
                            onOptionSelected(text)
                        }
                    )
                    .padding(vertical = 5.dp)
            ) {
                RadioButton(
                    selected = (text == selectedOption),
                    onClick = { onOptionSelected(text) }
                )
                Text(
                    text = text
                )
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

当前结果

在此输入图像描述

ngl*_*ber 5

您只需要verticalAlignment设置Row.

Row(
    Modifier
        .fillMaxWidth()
        .selectable(
            selected = (text == selectedOption),
            onClick = {
                onOptionSelected(text)
            }
        )
        .padding(vertical = 5.dp),
    verticalAlignment = Alignment.CenterVertically // <<<< THIS
) {
   ...
}
Run Code Online (Sandbox Code Playgroud)