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

Marcin Wisniowski

01/12/2022, 3:25 PM
How can I put a bigger composable in a smaller parent (both with fixed sizes), so that it's clipped? (like would happen by default with Views) My child composable just resizes itself to fit into the parent, which I don't want. I tried using
requiredWidth()
but that centers it inside the parent (it overflows to both sides), where I want it left-aligned and clipped on the right.
1
a

Adam Powell

01/12/2022, 3:36 PM
Use
Modifier.layout {}
to write a layout modifier that permits a larger max size for the child than the incoming constraints, then place the child as desired
then use a
.clip()
before your custom modifier
z

Zach Klippenstein (he/him) [MOD]

01/12/2022, 3:53 PM
I think you can also do
Modifier.wrapContentSize(align = Alignment.TopLeft, unbounded = true)
on the parent
🎉 1
m

Marcin Wisniowski

01/12/2022, 4:38 PM
Thank you,
clipToBounds()
+
wrapContentSize()
worked.