is it possible to expand Column content, to keep c...
# compose
p
is it possible to expand Column content, to keep content centered, but make it scrollable at the same time, if needed? I've tried following:
Copy code
Column(
    modifier = Modifier
        .fillMaxSize()
        // If I comment vertical scroll, it does what I want
        .verticalScroll(rememberScrollState()),
) {
    // I want to keep this on top
    Text(text = "title")

    // I want this to be expanded and centered
    Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
        Box(modifier = Modifier.size(300.dp).background(Color.Blue))
    }
}
s
Does this work for you?
Copy code
Column(fillMaxSize.verticalScroll()) {
  Text()
  Spacer(Modifier.weight(1f))
  Your content here
  Spacer(Modifier.weight(1f))
}
If the inner content is enough to make the column scrollable, the weights will then take up 0dp in height.
p
Hm, that works, thanks. I've managed to also find alternative solution
Copy code
Column(
    modifier = Modifier
        .fillMaxSize()
        .verticalScroll(rememberScrollState())
    ,
) {
    Text(text = "title")

    Box(modifier = Modifier.wrapContentSize().weight(1f)) {
        Box(
            modifier = Modifier
                .size(500.dp)
                .background(Color.Red),
        )
    }
}
think smart 1
s
Smart!
a
Simply setting
verticalArrangement = Arrangement.SpaceBetween
on the column should be enough.
This only works if you have an item at the bottom.
✔️ 1