0

I'm trying this compose :

@Composable
fun Card(text: String, imageVector: ImageVector) {
    androidx.compose.material.Card(
        modifier = Modifier.padding(4.dp)
    ) {
        Row(
            modifier = Modifier
                .fillMaxSize()
                .background(Color.Green)
        ) {

            Image(
                imageVector, contentDescription = null, modifier = Modifier
                    .padding(20.dp)
                    .size(96.dp)
            )
            Column(
                modifier = Modifier
                    .fillMaxHeight()
                    .background(Color.DarkGray),
                horizontalAlignment = Alignment.Start,
                verticalArrangement = Arrangement.Center
            ) {
                Text(
                    text = text,
                    style = MaterialTheme.typography.h6
                )
                Text(
                    text = text,
                    style = MaterialTheme.typography.subtitle2
                )
            }

        }

    }
}

I put some color because i wanted to know the space provided by the card to his childrens, and it's seems ok. Event if i'm making fillMaxHeight for the column, it s warping content and not filling height space. Suprisly, if i change fillMaxHeight by fillMaxWidth, it will fill the width. I'm asking why it doesn't do the same for the height with fillMaxHeight

Thanks

Z3nk
  • 365
  • 4
  • 17
  • I run your composable with `Card("Hello", Icons.Default.Propane)` in a sample project and [this](https://i.stack.imgur.com/K9OJk.png) is what I've got. Seems `fillMaxHeight` works correctly here. – Phil Dukhov Mar 29 '22 at 07:12
  • 1
    But it won't work if you're using it in a scrollable view, check out [this answer](https://stackoverflow.com/a/69395188/3585796) for details – Phil Dukhov Mar 29 '22 at 07:13
  • Yes the components itself is used in a LazyColumn, i will check this, thanks – Z3nk Mar 29 '22 at 07:15
  • My answer contains details for reasons why it doesn't work, also in `LazyColumn` you can use `Modifier.fillParentMaxHeight()` – Phil Dukhov Mar 29 '22 at 07:17
  • fillParentMaxHeight is unavailable because the compose is in a different kotlin file so doesn't have reference of his LazyColum parent. Is there a way to tell the compose that it have a LazyColumn reference in his parents ? My compose is just a whole file without LazyColumn reference (use in an other kotlin file) – Z3nk Mar 29 '22 at 07:19
  • Here is what i meant : https://imgur.com/x7pDQBX – Z3nk Mar 29 '22 at 07:22
  • 1
    Sure, `fun LazyItemScope.Card(...` – Phil Dukhov Mar 29 '22 at 07:24
  • If [my answer](https://stackoverflow.com/a/69395188/3585796) helped you, please give it an upvote. – Phil Dukhov Mar 29 '22 at 07:31

0 Answers0