Tomáš Procházka
10/30/2024, 2:01 PMCard
using Column
inside, but for some reason not propagating contentAlignment
😞 Why?
Card should be just Box with custom border design.
It is possible to use Modifier.align(Alignment.CenterHorizontally)
for Text
without Box
, but for some reason is it is not possible to align it vertically with that way, only horizontally.David
10/30/2024, 2:32 PMAs your saidusingCard
inside, but for some reason not propagatingColumn
😞 Why?contentAlignment
ElevatedCard
hosts a Column
(which you also can see by the ColumnScope) So contentAlignment will be referred to the horizontal alignment of things inside your column. It wouldn't make sense to center vertically in a column.
textAlign
doesn't align a text vertically either, see this code. It sort of makes sense if you think of that a text can be of multiple lines. It is not a layout, so it is sort of out of it's responsibility.
Sounds like what you are asking for is a ElevatedCard that does not provide a Column
out of the box. However, from my knowledge that doesn't exist.
This example shows it a bit more clearly:
@Preview
@Composable
fun test() {
ElevatedCard(modifier = Modifier.size(100.dp)) {
Text(
modifier =
Modifier.align(Alignment.CenterHorizontally).background(Color.Cyan).fillMaxHeight(),
textAlign = TextAlign.Center,
maxLines = 1,
text = "center",
)
}
}
Result would look like this:Stylianos Gakis
10/30/2024, 2:47 PMCard
composable which does not force you to be inside a Column which comes with these problems.Tomáš Procházka
10/30/2024, 5:28 PMTomáš Procházka
10/30/2024, 5:35 PMDavid
10/30/2024, 7:09 PM