https://kotlinlang.org logo
#compose
Title
# compose
b

bohregard

05/14/2020, 12:14 AM
What’s the easiest way to bottom align something
Copy code
Box(
    modifier = Modifier.fillMaxSize(),
    gravity = Alignment.BottomEnd
) {
    Column(modifier = Modifier.fillMaxHeight()) {
        ....
    }
    val icon = vectorResource(id = R.drawable.ic_home)
    FloatingActionButton(
        onClick = {
        }, modifier = Modifier.padding(20.dp)
    ) {
        Image(asset = icon, modifier = Modifier.preferredSize(24.dp))
    }
}
Is there a better way than the above?
m

Mihai Popa

05/14/2020, 10:37 AM
Are you trying to bottom align the FAB? If so, you can also make it part of the Column, and do something like this:
Copy code
Column {
        ....
   
    val icon = vectorResource(id = R.drawable.ic_home)
    FloatingActionButton(
        onClick = {
        }, modifier = Modifier.fillMaxHeight().wrapContentHeight(Alignment.Bottom).padding(20.dp)
    ) {
        Image(asset = icon, modifier = Modifier.preferredSize(24.dp))
    }
 }
fillMaxHeight().wrapContentHeight
will fill the remaining available space and allow the fab to be "wrap content" height with Alignment.Bottom being used to position the fab in the available space