Hi , How can I give layout margin around the view ...
# compose
c
Hi , How can I give layout margin around the view ? margin means the space outside the view, however padding means the space inside the view , why does it so complex to make here in the Compose ? I am not seeing any example of it ?
a
You can use Spacer for margins and Modifier.padding for padding
s
Margin and padding mean the same things in compose. What matters is where you add it. This acts like a margin:
Copy code
Modifier
    .padding(8.dp)
    .background(Color.Red)
This acts like a padding:
Copy code
Modifier
    .background(Color.Red)
    .padding(8.dp)
I'm not good at explaining so hopefully someone else can explain better
a
I agree. that's another way of doing
c
oh.. is that so .. ! I am suppressed
I was trying to leave space around the card view in order to align with background color of list view . I got mad searching all over place to make this happen
s
I think this was mentioned in a codelab or a video I don't remember which one
c
Please have look on this screen shot, this is what happened after adding padding
Copy code
Card(
    modifier = Modifier
        .padding(8.dp)
        .background(Color.Red)
) {
s
The Card's backgroundColor is being displayed over the background from your modifier
c
Okey, I got it, first put the background color and then have padding to make Margin
Copy code
Card(
    modifier = Modifier.background(Color.Red)
        .padding(8.dp)

)
This worked for me
Thank you
s
Great, so you needed a colored border around the card?
If yes, you can also pass a
border
to the
Card
c
How can I ? example ?
s
Copy code
Card(border = BorderStroke(2.dp, Color.Red))
c
Thanks
128 Views