Last active
March 15, 2023 13:20
-
-
Save munsra/9852b56532980e7cbd6dcdcf7977b8d3 to your computer and use it in GitHub Desktop.
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
class MainActivity : ComponentActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContent { | |
val constraints = ConstraintSet { | |
// Create the Constraint Components | |
val greenbox = createRefFor("greenbox") | |
val foodList = createRefFor("food_list") | |
val redBox = createRefFor("redbox") | |
// Define Contraints | |
constrain(greenbox){ | |
top.linkTo(parent.top) | |
start.linkTo(parent.start) | |
end.linkTo(parent.end) | |
width = Dimension.fillToConstraints | |
height = Dimension.value(100.dp) | |
} | |
constrain(foodList) { | |
top.linkTo(greenbox.bottom) | |
bottom.linkTo(redBox.top) | |
start.linkTo(parent.start) | |
height = Dimension.fillToConstraints | |
} | |
constrain(redBox) { | |
bottom.linkTo(parent.bottom) | |
start.linkTo(parent.start) | |
end.linkTo(parent.end) | |
width = Dimension.fillToConstraints | |
height = Dimension.value(100.dp) | |
} | |
} | |
ConstraintLayout(constraintSet = constraints, modifier = Modifier.fillMaxSize()) { | |
val itemsTest = listOf("Wiener Schnitzel", "Gianni's Ljubljanska", "Gorizia's Rose", "Gnocchi al Cinghiale", "Prosciutto Cotto e Kren", "Tiramisù", "Gubana", "Kipfel", "Salame con Aceto", "Repa", "Crauti", "Frittata alle Erbe", "Mortadella", "Brovada e Muset", "Gulash") | |
val scrollState = rememberScrollState() | |
Box( | |
modifier = Modifier | |
.background(Color.Green) | |
.layoutId("greenbox") | |
) | |
Column(modifier = Modifier.verticalScroll(scrollState).layoutId("food_list")) { | |
itemsTest.forEach { | |
Card(modifier = Modifier | |
.fillMaxWidth()){ | |
Box(modifier = Modifier.padding(16.dp)){ | |
Text(it) | |
} | |
} | |
} | |
} | |
Box( | |
modifier = Modifier | |
.background(Color.Red) | |
.layoutId("redbox") | |
) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment