Ask Your Question
2

How to position items in a row using Jetpack Compose?

asked 2021-06-30 11:00:00 +0000

lalupa gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-02-11 00:00:00 +0000

nofretete gravatar image

To position items in a row using Jetpack Compose, the Row() composable can be used. Within the Row() composable, items can be added using additional composable functions like Box(), Image(), Text(), etc. Each item can then be positioned within the Row() by specifying the arrangement of items using the Arrangement parameter.

Here is an example code snippet:

Row(
    horizontalArrangement = Arrangement.Center,
    verticalAlignment = Alignment.CenterVertically,
    modifier = Modifier.fillMaxWidth()
) {
    Box(
        contentAlignment = Alignment.Center,
        modifier = Modifier
            .padding(16.dp)
            .size(64.dp)
            .background(Color.Blue)
    ) {
        Text("Item 1", color = Color.White)
    }

    Image(
        painter = painterResource(id = R.drawable.image),
        contentDescription = "Item 2",
        modifier = Modifier
            .padding(16.dp)
            .size(64.dp)
            .clip(CircleShape)
    )
}

In this example, two items are added within the Row(): a Box() composable with a Text() inside it and an Image() composable. The Row() is positioned at the center horizontally using the horizontalArrangement parameter and vertically centered using the verticalAlignment parameter. The items are positioned within the Row() using their specific modifiers, including padding and size. The Box() composable has a blue background and the Image() is clipped to a circle shape.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-06-30 11:00:00 +0000

Seen: 1 times

Last updated: Feb 11 '22