This fills the entire screen for me as expected, b...
# compose
z
This fills the entire screen for me as expected, but the
Text
is not centered. Does anyone know why?
Copy code
AnimatedContent(
    modifier = Modifier.fillMaxSize(),
    contentAlignment = Center,
    targetState = x,
    content = { current ->
        Text("Center?")
    },
)
j
Because the Text fills up the whole area as well.
You can see that if you add
Copy code
Modifier.background(Color.Blue)
to the text composable.
c
Text itself has a textAlign parameter
j
or use
Copy code
.wrapContentSize()
z
So the
Modifier.fillMaxSize()
is added to my
Text
composable?
I guess that makes sense, I just never noticed this until now!
j
It’s not the modifier that is applied to the text but the constraints the layout applies to the content (the text in your case).
z
Well, TIL! Thanks for teaching me something new today! 👍🏽
j
You’r welcome 🙂 now you can solve my mystery above 😛
z
I tried to solve that a while back myself 😄 My use-case probably differs from yours, but ultimately I ended up having a minWeight value (0.001f) which when items were below that, just used 1.dp as their size. Otherwise the elements werent visible at all in my case. Otherwise, you might need to use BoxWithConstraints, or a custom layout (😅) to make it happen; for the former you could calculate how much the weight would equal to in width, and constrain it to 100.dp, etc.