Daniele Segato
11/23/2023, 11:08 PMHorizontalPager
(foundation)?
it is aligning the current item always on the left, I want it always in the center
see screenshot, code in threadDaniele Segato
11/23/2023, 11:08 PM@OptIn(ExperimentalFoundationApi::class)
@Preview
@Composable
private fun TestPager() {
val state = rememberPagerState(
pageCount = { 10 },
)
HorizontalPager(
state = state,
modifier = Modifier
.fillMaxWidth()
.background(Color.White),
pageSize = PageSize.Fixed(150.dp),
pageSpacing = 16.dp,
contentPadding = PaddingValues(horizontal = 16.dp),
) { page ->
Box(
modifier = Modifier
.fillMaxWidth()
.aspectRatio(1f)
.clip(RoundedCornerShape(16.dp))
.background(Color.Green)
) {
Text(
text = page.toString(),
modifier = Modifier.align(Alignment.Center),
fontSize = 50.sp,
)
}
}
}
Daniele Segato
11/23/2023, 11:11 PMDaniele Segato
11/23/2023, 11:21 PMDaniele Segato
11/24/2023, 12:03 AMDaniele Segato
11/24/2023, 12:21 AM@OptIn(ExperimentalFoundationApi::class)
@Preview
@Composable
private fun TestPager() {
val state = rememberPagerState(
pageCount = { 10 },
)
BoxWithConstraints(
Modifier.fillMaxWidth(),
) {
val horizontalPadding = (maxWidth - 150.dp) / 2
HorizontalPager(
state = state,
modifier = Modifier
.fillMaxWidth()
.background(Color.White),
pageSize = PageSize.Fixed(150.dp),
pageSpacing = 16.dp,
contentPadding = PaddingValues(horizontal = horizontalPadding),
) { page ->
Box(
modifier = Modifier
.fillMaxWidth()
.aspectRatio(1f)
.clip(RoundedCornerShape(16.dp))
.background(Color.Green)
) {
Text(
text = page.toString(),
modifier = Modifier.align(Alignment.Center),
fontSize = 50.sp,
)
}
}
}
}
raghunandan
12/04/2023, 3:19 AM