https://kotlinlang.org logo
#compose
Title
# compose
p

Philip Blandford

10/30/2020, 12:49 PM
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

sante

10/30/2020, 12:50 PM
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

Philip Blandford

10/30/2020, 12:51 PM
I still need the ConstraintLayout behaviour though
s

sante

10/30/2020, 12:51 PM
You can use constraintLayout as a child
p

Philip Blandford

10/30/2020, 12:53 PM
OK, but say I need to constrain item1 to a guideline, but have it underneath item2 which is constrained to the same guideline?
a

Andrey Kulikov

10/30/2020, 12:54 PM
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

Philip Blandford

10/30/2020, 12:55 PM
Ah - zIndex is just what I need, thanks!