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

Arun

03/04/2021, 4:07 PM
Hello! I want square
Box
items. Let’s say I have the following. How do I make sure the
Box
child composables are perfect squares? What value do I have to set it’s
height
to?
Copy code
@Composable
@Preview
fun PreviewSquareItems() {

    Row(modifier = Modifier.fillMaxWidth()) {
        val total = 2

        repeat(total) { index ->

            Box(
                modifier = Modifier
                    .weight(1f)
                    .height(245.dp) // how to find this height?
                    .clip(RoundedCornerShape(8.dp))
                    .background(color = Color.Blue),
            )

            if (index + 1 < total) {
                Spacer(modifier = Modifier.width(10.dp))
            }
        }
    }
}
s

Se7eN

03/04/2021, 4:08 PM
Try
Modifier.aspectRatio(1f)
👍 4
4
2 Views