0

So I had similar issue implementing the following Fill height for child in Row

There is answer https://stackoverflow.com/a/67678041/7767664 :

But it stops working as soon as you use ConstraintLayout:

@Composable
fun Test() {
    Row(
        modifier = Modifier
            .fillMaxWidth()
            .padding(horizontal = 16.dp)
            .background(
                Color.White,
                RoundedCornerShape(16.dp)
            )
            .clip(RoundedCornerShape(16.dp))
            .height(IntrinsicSize.Min) //Intrinsic measurement
    ) {
        Box(
            contentAlignment = Alignment.Center,
            modifier = Modifier
                .background(Color.Green)
                .width(20.dp)
                .fillMaxHeight()  //<--- fill max height
        ) {
            //
        }
        ConstraintLayout(modifier = Modifier.weight(1f).background(Color.Red)) {
            val (title, perHour) = createRefs()
            Text(
                text = "Title",
                color = Color.White,
                modifier = Modifier
                    .constrainAs(title) {
                        width = Dimension.preferredWrapContent
                        top.linkTo(parent.top, 16.dp)
                        linkTo(
                            start = parent.start,
                            end = perHour.start,
                            bias = 0f,
                            startMargin = 10.dp,
                            endMargin = 12.dp
                        )
                    }
            )
            Text(
                text = "£20.87/H",
                modifier = Modifier
                    .constrainAs(perHour) {
                        top.linkTo(parent.top, 16.dp)
                        end.linkTo(parent.end, 24.dp)
                    }
            )
        }
    }
}

enter image description here

The Box's height has become higher than height of second child (ConstraintLayout, if I use any other (Box/Row/Column) instead then it works fine)

Also ConstraintLayout doesn't take all the available width of Row even if weight is set to 1f

user924
  • 8,146
  • 7
  • 57
  • 139

0 Answers0