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

Grigorii Yurkov

10/22/2020, 12:54 PM
Please, help, what do I do wrong? I'm trying to make simple switch
h

Halil Ozercan

10/22/2020, 1:13 PM
Align is a special modifier for Box layout, also known as Stack. If you want to align in a Row, you can add
weight(1f)
modifier to Text composable.
Or simply use SpaceBetween for Row arrangement. I'm not sure if that would achieve the same result you were expecting.
g

Grigorii Yurkov

10/22/2020, 1:15 PM
Yeah, I tried to use Space with weight, but I didn't find Composable function for it
t

tieskedh

10/22/2020, 1:30 PM
There are different types of Alignment. Column supports vertical allignment and row supports horizontal allignment. You can call align for the surrounding type. Therefor your code does not compile. Choosing the right one would allow you to align. Don't need to know: The reason you're getting a more complex exception is because of DSLMarker (edited) Are you confusing Row (vertical) with Column (Horizontal)?
g

Grigorii Yurkov

10/22/2020, 1:31 PM
I need so-called "gravity"
For example in native android I can make a TextView with width=matchparent and gravity=end. As a result I get Textview at the end of the screen
z

Zach Klippenstein (he/him) [MOD]

10/22/2020, 2:03 PM
@tieskedh it's actually the other way around. Column and Row only support alignment on their "cross" axis, not the main one. So row only supports vertical alignment. This is why the dsl marker is throwing - you're passing
End
, which is a horizontal alignment, to the
align
modifier from the Row scope, which only accepts vertical alignments. @Grigorii Yurkov In compose, "gravity" and "alignment" mean the same thing (gravity modifiers and parameters were recently renamed to align). Both Halil's suggestions should work.
Yeah, I tried to use Space with weight, but I didn't find Composable function for it
Can you elaborate?
Spacer(Modifier.weight(1f))
should do the trick.
t

tieskedh

10/22/2020, 2:05 PM
@Zach Klippenstein (he/him) [MOD], oh, you're completely right! Thx for correcting!
g

Grigorii Yurkov

10/22/2020, 2:08 PM
@Zach Klippenstein (he/him) [MOD] Spacer works fine, thank you