Search code examples
androidandroid-jetpack-compose

Does Jetpack Compose have maxHeight and maxWidth like XML?


I'm looking to have a LazyColumn that initially wraps content height, but if it gets to a certain height (232dp) then it fixes its height at this. In XML I would have used maxHeight combined with wrapContent, but I cant find anything similar in Compose?


Solution

  • You can use heightIn modifier on LazyColumn like this

    LazyColumn(
        modifier = Modifier
            .heightIn(0.dp, 232.dp) //mention max height here 
            .widthIn(0.dp, 232.dp) //mention max width here 
    ) {                     
    }
    

    This will make sure that the height will not go above 232.dp if more items are added to lazycolumn