How can I clip the bottom of a composable, so that...
# compose
m
How can I clip the bottom of a composable, so that it's not higher than a given size? This seems very simple but I can't find a simple solution. I wrote a custom layout and that works, but surely there is an easier way.
s
This thread might be what you are looking for https://kotlinlang.slack.com/archives/CJLTWPH7S/p1676815475269369?thread_ts=1676767311.072529&cid=CJLTWPH7S By default when an item is bigger than its parent, it gets centered on it. Doing what Albert is suggesting here you can wrapContentHeight and give it the alignment you want (Alignment.Top in your case I presume) while making sure you pass your
unbounded = true
. Other than that, doing a custom layout is also an option as you say. Here’s how I did this to cut a specific amount from the top and from the bottom of an item that was bigger than what I wanted it to be for example.
m
Thank you,
wrapContentHeight(align = <http://Alignment.Top|Alignment.Top>, unbounded = true)
was what I needed. Much simpler than my custom layout. 😄
s
Yeap, I was in the exact same situation. I did a complex layout solution, then Albert came and saved the day, as usual 😅