I’m trying to make a layout, in this case a column, expand upward vertically on the press of a button. It’s not working. It’s only expanding downward.
Here is the code
When launched it displays a dark gray column. The column has a width of 200.dp and a height of 0.dp.
Beneath it is a button. When The button is clicked it will cause the column to expand to 200.dp in height.
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
ExpandingColumn()
}
}
}
@Composable
fun ExpandingColumn(){
var expanded by remember {
mutableStateOf(false)
}
Box(
modifier = Modifier
.fillMaxSize()
) {
Column(
modifier = Modifier
.offset(
x = 70.dp,
y = 250.dp
)
.animateContentSize()
.background(color = Color.DarkGray)
.width(200.dp)
.height(if (expanded) 200.dp else 0.dp)
) {
}
Button(
onClick = {expanded = !expanded},
modifier = Modifier
.offset(
x = 150.dp,
y = 600.dp
)
) {
Text(text = "Click")
}
}
}
The problem is whenever the column expands it goes downward. I want it to go upward. I can’t figure out how to do so.
Thanks for your time.