Hey! I’m trying to use a HorizontalPager with two ...
# compose
n
Hey! I’m trying to use a HorizontalPager with two Composables. But I need both of them to be the same height as the highest one. Is there an easy way to do this in compose that doesn’t cause a lot of recomposition? Right now when swiping the first Composable jumps a little once the other one is on screen. I don’t want to set a fixed height.
a
You're saying your pager has 2 indexes / screens? And you want to get the max height possible (could be screen A or screen B), and set that to the horizontal pager? I think you should be using a scrollable row instead. Pager is supposed to be lazy and dynamic. It doesn't sound like it fits the bill here.
My bad. I probably am not understanding your requirement properly.
s
i think you should set the height to horizontalpager and use that height as fillmaxheight to the children
👀 1
1
also you can use the property weight too
n
I fixed this issue for when there is room for all elements on the screen. But if user is using a smaller screen device then the second composable will be centered in the height of the first composable which is higher because the items can’t fit on the width of the screen. I need somehow to make the second composable in the HorizontalPager start at the top not center. The content is lazy and dynamic.
Meaning first screen will look like this:
Copy code
[ x ]    
[ x ]    
[ x ]
And the second composable will now have the same height as the first but as the content is not enough to fill the space height wise it will looke loike this:
Copy code
[   ]    
[ x ]    
[   ]
x being the actual content of the composable
Lol fixed it with verticalAlignment = Alignment.Top,…. Thanks 😅
1
a
Haha, always feels good to solve it yourself. Sometimes all you need to do is explain the problem to someone else 😁
🙌 1
n
You’re absolutely right. I’ve always wanted a rubber duck for that purpose - never bought one tho.. 🤔
💯 1