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

Ian Warwick

01/22/2021, 10:20 AM
Morning composers, I got a
Box
in a
Box
and I want to offset the inner box by
x
dps from the left, I tried left padding and offset though nothing seems to work
Copy code
Box(Modifier.background(Color.Red).width(128.dp).height(128.dp)) {
        Box(Modifier.background(Color.Green).width(32.dp).height(128.dp)) {

        }
    }
I want the inner box to have some space on the left hand size that I can specify hope that makes sense
a

allan.conda

01/22/2021, 10:26 AM
How about Modify.align it to the right?
padding for the inner box should also work though. might just be a problem with the ordering
i

Ian Warwick

01/22/2021, 10:28 AM
Cheers I wanted some exact positioning like 32.dp from the left or something though seems not to work like that, maybe margin is something I need though don't seem to find a Modifier for that
a

allan.conda

01/22/2021, 10:29 AM
there’s no margin in compose. But what you meant by margin is adding padding aT the top-most order
let me make a poc really quickly
🙏 1
i

Ian Warwick

01/22/2021, 10:29 AM
cheers!
This is what I tried
Copy code
Box(Modifier.background(Color.Red).width(128.dp).height(128.dp)) {
        Box(Modifier.background(Color.Green).width(32.dp).height(128.dp).offset(32.dp)) {

        }
    }
and I get this in Preview
I tried padding start and padding left to get the green bar offset where I want it (say 32.dp in) though still did not move the green bar
a

allan.conda

01/22/2021, 10:31 AM
you want this right?
ah, sorry, should just be padding(start = 16.dp)
i

Ian Warwick

01/22/2021, 10:32 AM
kinda just the green bar to not have padding at top or bottom
aha! I think it might be Modifier ordering?
a

allan.conda

01/22/2021, 10:32 AM
yep
👍 1
i

Ian Warwick

01/22/2021, 10:32 AM
I put mine last and not first in the modifier list
a

allan.conda

01/22/2021, 10:32 AM
modifier order matters
i

Ian Warwick

01/22/2021, 10:32 AM
nice one!
a

allan.conda

01/22/2021, 10:33 AM
Compose Preview is ridiculously slow…
i

Ian Warwick

01/22/2021, 10:33 AM
yeh thanks! 🙂 it works
yeh and sometimes bugs out I think
a

allan.conda

01/22/2021, 10:33 AM
i

Ian Warwick

01/22/2021, 10:33 AM
lovely cheers works
4 Views