jordond
01/08/2024, 1:47 AMColumn(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
modifier = Modifier.fillMaxSize(),
) {
HorizontalPager(
state = pagerState,
beyondBoundsPageCount = 1,
contentPadding = PaddingValues(horizontal = 32.dp),
pageSpacing = 16.dp,
) { page ->
Box(
modifier = Modifier
.size(200.dp)
.background(if (page % 2 == 0) Color.Red else Color.Blue),
)
}
}
But it produces something like the attached image.
Can anyone help me out?jordond
01/08/2024, 1:53 AMval density = LocalDensity.current
var componentHeight by remember { mutableStateOf(200.dp) }
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
modifier = Modifier.fillMaxSize(),
) {
HorizontalPager(
state = pagerState,
beyondBoundsPageCount = 1,
pageSize = PageSize.Fixed(componentHeight),
contentPadding = PaddingValues(horizontal = componentHeight / 2),
pageSpacing = 32.dp,
) { page ->
Box(
modifier = Modifier
.size(200.dp)
.background(if (page % 2 == 0) Color.Red else Color.Blue)
.onGloballyPositioned { coordinates ->
componentHeight = with(density) {
coordinates.size.height.toDp()
}
},
)
}
}
But how hacky is that?jordond
01/08/2024, 1:55 AM