I am not able to set height of card composable. However if I place Card() inside a Column then I am able to do it. Why is that?
@Composable
fun HeroListItem(
hero: Hero,
// modifier: Modifier = Modifier
) {
Card(
modifier = Modifier
.height(200.dp),
border = BorderStroke(
3.dp, MaterialTheme.colorScheme.error
),
elevation = CardDefaults.cardElevation(
defaultElevation = 2.dp
)
) {
) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
.background(color = MaterialTheme.colorScheme.primaryContainer),
verticalAlignment = Alignment.CenterVertically
) {
Column(
modifier = Modifier
.weight(0.8f)
.padding(8.dp)
) {
Text(
text = stringResource(id = R.string.hero2),
style = MaterialTheme.typography.displaySmall
)
Text(
text = stringResource(id = R.string.description2),
style = MaterialTheme.typography.bodyLarge
)
}
Spacer(Modifier.width(16.dp)) // Add spacing between the columns
Column(modifier = Modifier.weight(0.2f)) { // Adjust the weight to desired value
Image(
painter = painterResource(id = R.drawable.android_superhero2),
contentDescription = null,
alignment = Alignment.BottomEnd,
contentScale = ContentScale.FillWidth,
modifier = Modifier
.size(72.dp)
.clip(RoundedCornerShape(8.dp))
)
}
}
}
I have checked that no external modifier is doing anything to Card tried commenting all others inside also still card height is like full screen.
You can see red border around the card screenshot off app
I tried almost everything that I have idea about searched everywhere. Actually I got desired results by using wrapping with Column and using requiredHeight modifier but want to understand why is it working this way.