I'm trying to build something similar to the following using Jetpack Compose ConstraintLayout.
I want to understand how can I create a vertical chain with respect to the Image. When I try to use the createVerticalChain()
function, that overrides my given constraints and chains it w.r.t the parent instead.
Here's my current code if that's any helpful
@Composable
fun GreetingWithConstraintLayout(name: String) {
ConstraintLayout(modifier = Modifier.fillMaxSize()) {
val(ivIcon, tvHello, tvBye) = createRefs()
createVerticalChain(tvBye, tvHello, chainStyle = ChainStyle.Packed)
Image(
painter = painterResource(id = R.drawable.ic_launcher_background),
contentDescription = null,
modifier = Modifier
.size(80.dp)
.clip(CircleShape)
.border(1.5.dp, MaterialTheme.colors.primary, CircleShape)
.constrainAs(ivIcon) {
start.linkTo(parent.start)
top.linkTo(parent.top)
}
)
Text(
text = "Hello $name!",
modifier = Modifier.constrainAs(tvHello) {
start.linkTo(ivIcon.end, 8.dp)
top.linkTo(ivIcon.top)
bottom.linkTo(tvBye.top)
}
)
Text(
text = "Bye $name!",
modifier = Modifier.constrainAs(tvBye) {
start.linkTo(tvHello.start)
top.linkTo(tvHello.bottom)
bottom.linkTo(ivIcon.bottom)
}
)
}
}
I can't find any example similar to this use case online. I'm not even sure if this can be done? Thank you!