0

I am trying to learn jetpack compose and I've learnt to use spacer for items, but I still do not know how to add margin to an image on the left or right, any idea?

Screen:

enter image description here

code:

    Column(
        modifier = Modifier.fillMaxSize()
    ) {
        Spacer(modifier = Modifier
            .padding(50.dp)

            )
        Image(
            painter = painterResource(id = R.drawable.image),
            contentDescription = null,
            contentScale = ContentScale.Crop,
            modifier = Modifier
                .size(80.dp)
                .clip(CircleShape)

        )
}
a_local_nobody
  • 7,947
  • 5
  • 29
  • 51

1 Answers1

0

There is actually almost uncountable different ways to achieve this , I would using a Row() instead of a Column() in your case and simply add a spacer with your needed space as follows

Spacer(modifier = Modifier.width(50.dp))

or if you want to align the image to the left with the same approach your function would look like that

Row(
                modifier = Modifier.fillMaxSize()
            ) {
                Spacer(modifier = Modifier.weight(1f))
                
                Image(
                    painter = painterResource(id = R.drawable.ic_image),
                    contentDescription = null,
                    contentScale = ContentScale.Crop,
                    modifier = Modifier
                        .size(80.dp)
                        .clip(CircleShape)

                )
            }