Guilherme Delgado
09/25/2023, 12:07 PMGuilherme Delgado
09/25/2023, 12:08 PMBox(
modifier = Modifier
.weight(1f)
.fillMaxSize()
.background(Color.White),
contentAlignment = Alignment.Center
) {
AnimatedContent(
targetState = value,
transitionSpec = ...
) {
Text(
text = it,
maxLines = 1,
fontSize = 18.sp,
)
}
}
this does not (it will stay on top instead on center):
Box(
modifier = Modifier
.weight(1f)
.fillMaxSize()
.background(Color.White),
contentAlignment = Alignment.Center
) {
AnimatedContent(
targetState = value,
transitionSpec = ...,
modifier = Modifier.fillMaxSize() <<<<<<<<<<<<<<<<<<<< same output
) {
Text(
text = it,
maxLines = 1,
fontSize = 18.sp,
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxSize() <<<<<<<<<<<<<<<<<<<< same output
)
}
}
Stylianos Gakis
09/25/2023, 12:16 PMAnimatedContent
take the exact same size as Box()
this way?
Try adding some borders
around your composables to see what space they take up instead, I canāt deduce just from the code whatās going wrong.Guilherme Delgado
09/25/2023, 12:20 PMmodifier = Modifier.fillMaxSize() <<<<<<<<<<<<<<<<<<<< same output
it does yes (if I instead add to Text same behaviour).Stylianos Gakis
09/25/2023, 12:21 PMGuilherme Delgado
09/25/2023, 12:22 PMGuilherme Delgado
09/25/2023, 12:23 PMmodifier = Modifier.fillMaxSize().border(1.dp, Color.Yellow)
the blue (added by the preview) is with:
modifier = Modifier.border(1.dp, Color.Yellow)
Guilherme Delgado
09/25/2023, 12:24 PMStylianos Gakis
09/25/2023, 12:27 PMGuilherme Delgado
09/25/2023, 12:28 PMStylianos Gakis
09/25/2023, 12:28 PMmatchParentSize()
on the AnimatedContent
, and have the text without any size modifiers, and rely on contentAlignment
from AnimatedContent
to put the text at the center?Stylianos Gakis
09/25/2023, 12:29 PMGuilherme Delgado
09/25/2023, 12:30 PMStylianos Gakis
09/25/2023, 12:30 PMfillMaxSize
?Guilherme Delgado
09/25/2023, 12:31 PMStylianos Gakis
09/25/2023, 12:32 PMGuilherme Delgado
09/25/2023, 12:32 PMStylianos Gakis
09/25/2023, 12:32 PMGuilherme Delgado
09/25/2023, 12:33 PMGuilherme Delgado
09/25/2023, 12:33 PMStylianos Gakis
09/25/2023, 12:33 PMAnimatedContent(
targetState = value,
transitionSpec = ...,
modifier = Modifier.matchParentSize(),
) {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text(
text = it,
maxLines = 1,
fontSize = 18.sp,
textAlign = TextAlign.Center,
)
}
}
Stylianos Gakis
09/25/2023, 12:33 PMGuilherme Delgado
09/25/2023, 12:33 PMGuilherme Delgado
09/25/2023, 12:33 PMGuilherme Delgado
09/25/2023, 12:34 PMGuilherme Delgado
09/25/2023, 12:34 PMStylianos Gakis
09/25/2023, 12:35 PMStylianos Gakis
09/25/2023, 12:36 PMGuilherme Delgado
09/25/2023, 12:37 PM