iroyo
04/18/2023, 3:35 PM@Preview
@Preview(fontScale = 3f)
@Composable
fun TestCheckbox2() {
Row(verticalAlignment = Alignment.CenterVertically) {
Icon(
painter = painterResource(id = R.drawable.ic_checkbox_checked), contentDescription = null,
)
Text(
text = "Line 1\nline2",
)
}
}
I one to avoid using a constraint layout and add “invisible” lines to align it.
First image what I have, second image what I want to achieveTravis Griggs
04/18/2023, 4:17 PM@Preview
@Preview(fontScale = 3f)
@Composable
fun TestCheckbox3() {
Column {
Row(verticalAlignment = Alignment.CenterVertically) {
Icon(Icons.Default.CheckBox, contentDescription = null)
Text(text = "Line 1")
}
Row(verticalAlignment = Alignment.CenterVertically) {
Icon(Icons.Default.CheckBox, contentDescription = null, modifier = Modifier.alpha(0f))
Text(text = "line 2")
}
}
}
Assuming Solution 2:
@Preview
@Preview(fontScale = 3f)
@Composable
fun TestCheckbox4() {
Row(modifier = Modifier.height(IntrinsicSize.Min), verticalAlignment = <http://Alignment.Top|Alignment.Top>) {
Icon(
Icons.Default.CheckBox,
contentDescription = null,
modifier = Modifier.fillMaxHeight(0.5f)
)
Text(text = "Line 1\nline2")
}
}
Travis Griggs
04/18/2023, 4:18 PMefemoney
04/18/2023, 6:34 PMModifier.alignBy
on the icon & Modifier.alignByBaseline
on the text.efemoney
04/18/2023, 6:50 PMephemient
04/19/2023, 5:19 AMIcon
doesn't emit alignment lines, so unfortunately Modifier.alignByBaseline()
won't helpephemient
04/19/2023, 5:20 AMephemient
04/19/2023, 5:21 AMRow {
var firstLineHeight by remember { mutableStateOf(0f) }
Icon(
...,
modifier = Modifier.heightIn(min = with(LocalDensity.current) { firstLineHeight.toDp() })
)
Text(
...,
onTextLayout = { firstLineHeight = it.getLineBottom(0) }
)
}
Oleksandr Balan
04/19/2023, 5:46 AMRow {
Box(contentAlignment = Alignment.Center) {
Text(text = "")
Icon(
imageVector = Icons.Default.List,
contentDescription = null,
)
}
Text(
text = "Line 1\nline2",
)
}
iroyo
04/19/2023, 9:16 AMephemient
04/19/2023, 7:14 PM