Created
May 29, 2024 19:00
-
-
Save amodkanthe/256d0e5f46c51c39d342ae8303cd5378 to your computer and use it in GitHub Desktop.
Guideline and Barrier
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() { | |
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