Created
May 29, 2024 17:14
-
-
Save amodkanthe/41bb6b434892b0a536255d38c75bf77b to your computer and use it in GitHub Desktop.
ConstraintLayout First Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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