https://kotlinlang.org logo
#compose
Title
# compose
k

Kata

02/16/2022, 8:01 AM
Hi, with compose I would like to put a view under an another view inside a
constraint layout
, linking the bottom view to the view on the top. This works fine until I decide not to display the top view for some reason. At this point the view at the bottom is not displayed at the right place. This makes sense since the
Modifier.constrainAs
is not set up for the top view. What would be the correct solution for this issue?
My current solution is adding a Spacer but that is a bit ugly
Copy code
if (visible) {
    Text(
        text = "text",
        modifier = Modifier.constrainAs(text) {
            top.linkTo(title.bottom, 6.dp)
            start.linkTo(title.start)
        }
    )
} else {
    Spacer(
        modifier = Modifier.constrainAs(text) {
            top.linkTo(title.bottom)
            start.linkTo(title.start)
        }
    )
}
This way the
text
constraint works