Fill height for child in Row when one of them is ConstraintLayout
Asked Answered
W

0

0

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

There is answer https://mcmap.net/q/369869/-fill-height-for-child-in-row :

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

Winter answered 11/4, 2023 at 22:4 Comment(4)
What version of ConstraintLayout are you using. This might have been fixed in 1.1.0 alpha06Catholicize
@Catholicize no, it's stable version - "androidx.constraintlayout:constraintlayout-compose:1.0.1"Winter
It a bug should be fixed in 1.1.0-alpha06 07 08 09 etc.Catholicize
@Catholicize do you know for sure or are you just guessing it? can you please provide a link with info about such fix?Winter

© 2022 - 2024 — McMap. All rights reserved.