tieskedh
12/13/2020, 2:59 PMRow {
Text(
"h4 text",
style = MaterialTheme.typography.h4,
)
Text("my icon")
}
I saw that fontsize had a lineHeight, and a baselineshift.
The thing I don't get is that the baselineshift is a multiplier.
How can I compute the top with it?
Or is there some other way?Dominaezzz
12/13/2020, 3:35 PMtieskedh
12/13/2020, 3:42 PMtieskedh
12/13/2020, 3:46 PMBox {
Row {
Text(
"h4 text",
modifier = Modifier.padding(end = 10.dp),
style = MaterialTheme.typography.h4,
onTextLayout = {
it.firstBaseline
}
)
Row(
modifier = Modifier
) {
Text("my icon")
}
}
Spacer(
Modifier.padding(top = 11.dp)
.fillMaxWidth()
.height(1.dp)
.background(Color.Black)
)
}
Kshitij Patil
12/13/2020, 3:47 PMConstraintLayout
or use custom Layout to measure height of individual text and positionY
accordinglytieskedh
12/13/2020, 3:50 PMKshitij Patil
12/13/2020, 3:57 PMtieskedh
12/13/2020, 3:58 PMText(
"h4 text",
modifier = Modifier.padding(end = 10.dp)
.background(Color.Red),
style = MaterialTheme.typography.h4,
onTextLayout = {
it.firstBaseline
}
)
tieskedh
12/13/2020, 3:58 PMKshitij Patil
12/13/2020, 4:00 PMtieskedh
12/13/2020, 4:01 PMMaterialTheme.typography.h4.baselineShift
But I don't know how to use it.tieskedh
12/13/2020, 4:03 PMRow(modifier) {
Text(
"some text",
modifier = Modifier.padding(end = 10.dp),
style = MaterialTheme.typography.h4
)
Column {
Row {
Icon(Icons.Default.DateRange)
Text("another text)
}
}
The problem is that if i color the background of the H4, it colors more then only the real text.
Therefor, I guess some padding is build in?
I want to know that padding (in this case 10.dp), such that I can align by the top of the text.
You suggested to use measuring of the childs, but does that work if more then the H4 is colored?Kshitij Patil
12/13/2020, 4:13 PMText
Composable but I believe it'll if you measure the height and use the padding with modifier, better give it a try.tieskedh
12/13/2020, 4:14 PMVinay Gaba
12/13/2020, 11:09 PMModifier.alignBy
. Here’s an example - https://github.com/vinaygaba/Learn-Jetpack-Compose-By-Example/blob/master/app/src/[…]ample/jetpackcompose/layout/ViewLayoutConfigurationsActivity.kttieskedh
12/14/2020, 8:37 AM