Chethan

    Chethan

    1 year ago
    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 ?
    Ali Albaali

    Ali Albaali

    1 year ago
    You can use Spacer for margins and Modifier.padding for padding
    s

    Se7eN

    1 year ago
    Margin and padding mean the same things in compose. What matters is where you add it. This acts like a margin:
    Modifier
        .padding(8.dp)
        .background(Color.Red)
    This acts like a padding:
    Modifier
        .background(Color.Red)
        .padding(8.dp)
    I'm not good at explaining so hopefully someone else can explain better
    Ali Albaali

    Ali Albaali

    1 year ago
    I agree. that's another way of doing
    Chethan

    Chethan

    1 year ago
    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

    1 year ago
    I think this was mentioned in a codelab or a video I don't remember which one
    Chethan

    Chethan

    1 year ago
    Please have look on this screen shot, this is what happened after adding padding
    Card(
        modifier = Modifier
            .padding(8.dp)
            .background(Color.Red)
    ) {
    s

    Se7eN

    1 year ago
    The Card's backgroundColor is being displayed over the background from your modifier
    Chethan

    Chethan

    1 year ago
    Okey, I got it, first put the background color and then have padding to make Margin
    Card(
        modifier = Modifier.background(Color.Red)
            .padding(8.dp)
    
    )
    This worked for me
    Thank you
    s

    Se7eN

    1 year ago
    Great, so you needed a colored border around the card?
    If yes, you can also pass a
    border
    to the
    Card
    Chethan

    Chethan

    1 year ago
    How can I ? example ?
    s

    Se7eN

    1 year ago
    Card(border = BorderStroke(2.dp, Color.Red))
    Chethan

    Chethan

    1 year ago
    Thanks