https://kotlinlang.org logo
c

Chethan

10/09/2020, 11:22 AM
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

Ali Albaali

10/09/2020, 12:53 PM
You can use Spacer for margins and Modifier.padding for padding
s

Se7eN

10/09/2020, 1:10 PM
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

Ali Albaali

10/09/2020, 1:11 PM
I agree. that's another way of doing
c

Chethan

10/09/2020, 1:12 PM
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

Se7eN

10/09/2020, 1:15 PM
I think this was mentioned in a codelab or a video I don't remember which one
c

Chethan

10/09/2020, 1:16 PM
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

Se7eN

10/09/2020, 1:19 PM
The Card's backgroundColor is being displayed over the background from your modifier
c

Chethan

10/09/2020, 1:20 PM
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

Se7eN

10/09/2020, 1:21 PM
Great, so you needed a colored border around the card?
If yes, you can also pass a
border
to the
Card
c

Chethan

10/09/2020, 1:27 PM
How can I ? example ?
s

Se7eN

10/09/2020, 1:28 PM
Copy code
Card(border = BorderStroke(2.dp, Color.Red))
c

Chethan

10/09/2020, 1:52 PM
Thanks
7 Views