Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 499
user21830153 Avatar asked Oct 25 '25 14:10

user21830153


1 Answers

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
}
like image 133
Viktor Skliarov Avatar answered Oct 27 '25 05:10

Viktor Skliarov