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

rajesh

08/18/2021, 11:41 AM
Is there any way to let compose know that composable1() should be placed in upper half of screen and composable2() should be placed in lower half of screen (like instagram profile page), no matter at what time data arrive from network. (post data could arrive before user data)
Found the solution
Copy code
Composable1(modifier = Modifier.fillMaxSize(0.5f))
Spacer()
Composable2()
t

than_

08/18/2021, 1:27 PM
that or you can use constraint layout
c

Colton Idle

08/18/2021, 6:42 PM
Copy code
Composable1(modifier = Modifier.weight(1f))
Spacer()
Composable2(modifier = Modifier.weight(1f))
having weight set to 1 will make sure both take up 50%
t

Tash

08/18/2021, 8:24 PM
how much space would Spacer() take in this case? assuming you could give it a static height and it should work well with the two weighted composables? 🤔
c

Colton Idle

08/18/2021, 8:27 PM
Yep, good point. I just wanted to point out that something like
Copy code
Composable1(modifier = Modifier.fillMaxSize(0.5f))
Spacer()
Composable2(modifier = Modifier.fillMaxSize(0.5f))
would not work, because I did this yesterday, and so Composable2 will only take up 50% of the rest of the space, which is 25% of the space. So using something like weight might be appropriate.
t

Tash

08/20/2021, 5:11 PM
oh yeah. i always tend to get confused about weights in situations like this 😓