Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save amodkanthe/41bb6b434892b0a536255d38c75bf77b to your computer and use it in GitHub Desktop.
Save amodkanthe/41bb6b434892b0a536255d38c75bf77b to your computer and use it in GitHub Desktop.
ConstraintLayout First Example
@Preview
@Composable
fun ConstraintLayoutView() {
var count by remember { mutableStateOf(0) }
ConstraintLayout(modifier = Modifier.fillMaxSize()) {
val (button, text) = createRefs()
Button(
onClick = { count++ },
modifier = Modifier.constrainAs(button) {
width = Dimension.value(200.dp)
height = Dimension.value(56.dp)
top.linkTo(parent.top, margin = 16.dp)
bottom.linkTo(parent.bottom, margin = 16.dp)
start.linkTo(parent.start, margin = 16.dp)
end.linkTo(parent.end, margin = 16.dp)
}
) {
Text("Click")
}
Text(
"Count:${count}",
Modifier.constrainAs(text) {
top.linkTo(button.bottom, margin = 16.dp)
start.linkTo(button.start, margin = 16.dp)
end.linkTo(button.end, margin = 16.dp)
}
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment