juske
juske

Reputation: 312

Set height to Row in Jetpack Compose equivalent to wrap_content in xml

I have this row with two buttons and one divider.
I had set the weight so the buttons can have the same width.

Row(modifier = Modifier
    .fillMaxWidth()
    .padding(horizontal = 5.dp)
    .height(300.dp)
) {
    Button(
        stringResource(id = R.string.ha_topos_button_description),
        Modifier.weight(1f)
    )
    Divider(whichType = "vertical")
    Button(
        stringResource(id = R.string.ha_gyms_button),
        Modifier.weight(1f)
    )
}

If I don't set the .height(300.dp) property to the Row, it disappears. I don't want to set any hardcoded height, I just want the row to have its "wrap_content" height.
How can I do it on Compose???

Upvotes: 2

Views: 4009

Answers (1)

Johann
Johann

Reputation: 29877

Use wrapContentHeight to have the row wrap to the content's height:

Row(modifier = Modifier
    .fillMaxWidth()
    .padding(horizontal = 5.dp)
    .wrapContentHeight()
) {
    Button(
        stringResource(id = R.string.ha_topos_button_description),
        Modifier.weight(1f)
    )
    Divider(whichType = "vertical")
    Button(
        stringResource(id = R.string.ha_gyms_button),
        Modifier.weight(1f)
    )
}

Upvotes: 3

Related Questions