https://kotlinlang.org logo
#compose
Title
# compose
c

chris

03/09/2021, 3:07 AM
Given some type of container how would I draw only the bottom half of a piece of text within the given container? Such that the top of the half of text (aka the middle vertical point if the text was fully drawn) touches the top of the parent container and the bottom touches the bottom of the parent container?
I've tried shapes, offsets, and graphic layer. I keep ending up with the top half of the text cut off and offset when I need the bottom
n

Nader Jawad

03/09/2021, 3:39 AM
Sounds like you might need to use
Modifier.clip
with a rect shape that is half of the size of the text composable. Do you have a screenshot or a mock of what you are trying to build?
a

Albert Chang

03/09/2021, 4:02 AM
This should work:
Copy code
Text(text = "Text", modifier = Modifier.clipToBounds().layout { measurable, _ ->
    val placeable = measurable.measure(Constraints())
    val halfHeight = placeable.height / 2
    layout(placeable.width, halfHeight) {
        placeable.place(0, -halfHeight)
    }
})
c

chris

03/09/2021, 4:26 PM
This worked perfectly! Thanks!