In a constraintLayout, how can I guarantee that on...
# compose
p
In a constraintLayout, how can I guarantee that one element will be underneath the others? Up until alpha05 I was wrapping them in Surfaces and setting the elevation, which didn't feel ideal but it worked. Now in alpha06 that doesn't work any more and they just appear in an order that varies with refreshes.
s
You should use a
Box()
for treating components like a stack, it's its default behavior
It takes into account the order in which you call children composables so each one is above the previous one
p
I still need the ConstraintLayout behaviour though
s
You can use constraintLayout as a child
p
OK, but say I need to constrain item1 to a guideline, but have it underneath item2 which is constrained to the same guideline?
a
it is a bug that ConstraintLayout is not using the order in which you compose items as the drawing order, which is fixed here: https://android-review.googlesource.com/c/platform/frameworks/support/+/1471842. to be released in the next release
👍 1
in the meantime you can apply different Modifier.zIndex() for your items to define the drawing order
p
Ah - zIndex is just what I need, thanks!