Search code examples
androidkotlinalignment

align() won't work in case of using Box() in Kotlin JetPack Compose


enter image description herecan anyone help with this problem? Trying to compile this part of code, but it request imports, but won't work after that also. Thanks. I just took that code from https://developer.android.com/jetpack/compose/modifiers, so i don't understand why it wont work, cause i imported all packages that i can. But i see some errors in import section. Sorry my English, thanks.

Box( Modifier.align().fillMaxHeight().width( 50.dp ).background(Color.Blue) )

I've tried to import that align, but it won't helps.


Solution

  • To align content inside a Box you need to use contentAlignment:

    Box(
        modifier = Modifier
            .fillMaxHeight()
            .width(50.dp)
            .background(Color.Blue),
        contentAlignment = Alignment.Center
    ) {
        //some code
    }