Feroz Khan
Feroz Khan

Reputation: 2836

How to centre elements in Jetpack Compose Desktop Column

Working on desktop application with Jetpack Compose and unable to center elements in a Column as horizontalAlignment attribute is not working. I've also seen many other answers saying to use horizontalArrangment but that is also not working for desktop application.

enter image description here

Update: I've imported Alignment from androidx.compose.ui now and able to use CenterHorizontally and error is gone but it's still not getting in centre.

Upvotes: 0

Views: 659

Answers (2)

Şahan Şenvar
Şahan Şenvar

Reputation: 48

You need to use Align.CenterHorizontally and add it if you don't want to check your import

import androidx.compose.ui.Alignment

Column (
      modifier = Modifier.fillMaxWidth(),
      verticalArrangement = Arrangement.Center,
      horizontalAlignment = Alignment.CenterHorizontally
    ) {
      //content here
    }

Upvotes: 0

Steven Chris
Steven Chris

Reputation: 61

you need to add


Column(
    modifier = Modifier
        .fillMaxWidth(),
    horizontalAlignment = Alignment.CENTRE
){
   ....
}

because u need to state max width for the apps or you need to define the width/height of the column so that horizontal can be placed on the centre.

Upvotes: 2

Related Questions