Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save amodkanthe/256d0e5f46c51c39d342ae8303cd5378 to your computer and use it in GitHub Desktop.
Save amodkanthe/256d0e5f46c51c39d342ae8303cd5378 to your computer and use it in GitHub Desktop.
Guideline and Barrier
@Preview
@Composable
fun ConstraintLayoutView() {
ConstraintLayout(modifier = Modifier.fillMaxSize()) {
val (text1, text2, button) = createRefs()
val guideline = createGuidelineFromStart(0.5f)
val barrier = createBottomBarrier(text1, text2)
Button(
onClick = { },
modifier = Modifier.constrainAs(button) {
width = Dimension.value(200.dp)
height = Dimension.value(56.dp)
top.linkTo(barrier, margin = 8.dp)
start.linkTo(parent.start, margin = 8.dp)
end.linkTo(parent.end, margin = 8.dp)
}
) {
Text("I am below two views")
}
Text(
"this is a variable lenght text",
Modifier.constrainAs(text1) {
top.linkTo(parent.top, margin = 8.dp)
start.linkTo(parent.start, margin = 8.dp)
end.linkTo(guideline, margin = 8.dp)
width = Dimension.fillToConstraints
}
)
Text(
"this is another textview with variable lenght",
Modifier.constrainAs(text2) {
top.linkTo(parent.top, margin = 8.dp)
start.linkTo(guideline, margin = 8.dp)
end.linkTo(parent.end, margin = 8.dp)
width = Dimension.fillToConstraints
}
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment