Search code examples
androidkotlinandroid-jetpack-composeandroid-jetpack-compose-material3

jetpack compose horizontal constaints don't see to work


i want to position a box in the right of the container here is the code i have:

Row(
                modifier = Modifier
                    .fillMaxWidth()
                    .background(Color.Cyan)

            ){
                ConstraintLayout {
                    val (leftt,middle,rightt) = createRefs()

                    Box(
                        modifier = Modifier.fillMaxHeight()
                            .width(50.dp)
                            .background(Color.Yellow)
                            .constrainAs(rightt){
                                end.linkTo(parent.end)
                            }
                    ){
                        Text("s99")
                    }

i tried using

absoluteRight

but it didn't work


Solution

  • I'm not sure but as per my understanding, the view you are looking for looks like this?

    UI

    If yes, Here is the code snippet. I just modified your code.

        Row(
            modifier = Modifier
                .fillMaxWidth()
                .background(Color.Cyan)
                .wrapContentSize(Alignment.TopEnd)
        ) {
            Box(
                modifier = Modifier
                    .fillMaxHeight()
                    .width(50.dp)
                    .background(Color.Yellow)
            ) {
                Text("s99")
            }
        }
    
    

    I hope this helps you well.