OG
02/07/2022, 8:59 PMZun
02/07/2022, 9:14 PMOG
02/07/2022, 9:27 PMdewildte
02/07/2022, 10:53 PMOG
02/07/2022, 11:20 PMraghunandan
06/08/2022, 2:16 AMOG
06/20/2022, 10:21 PMsteelahhh
06/21/2022, 4:36 AMraghunandan
07/24/2022, 4:02 PMOG
07/31/2022, 8:44 PMraghunandan
08/01/2022, 2:51 AM@OptIn(ExperimentalPagerApi::class)
@Composable
fun PagerDemo(modifier: Modifier = Modifier) {
HorizontalPager(
count = 30,
// Not sure if i can remove this hardcoded value.
contentPadding = PaddingValues(horizontal = 160.dp),
itemSpacing = 8.dp,
modifier = modifier
) { page ->
Card(
modifier = Modifier
.graphicsLayer {
val pageOffset = calculateCurrentOffsetForPage(page).absoluteValue
// Set the item alpha and scale based on the distance from the center
val percentFromCenter = 1.0f - (pageOffset / (5f / 2f))
val itemScale = 0.5f + (percentFromCenter * 0.5f).coerceIn(0f, 1f)
val opacity = 0.25f + (percentFromCenter * 0.75f).coerceIn(0f, 1f)
alpha = opacity
scaleY = itemScale
scaleX = itemScale
}
.clip(CircleShape)
.size(50.dp)
) {
Image(
painter = painterResource(R.drawable.ic_launcher_background),
contentDescription = null,
modifier = Modifier
.size(50.dp)
)
}
}
}
contentPadding = PaddingValues(horizontal = 160.dp)
This is something that is hardcoded would like to replace this.OG
08/01/2022, 2:42 PMBoxWithConstraints
to get the available width, you know your item width (e.g. 50dp), and then you can do some easy math to figure out the content padding without hardcoding, so the first item is centeredraghunandan
08/01/2022, 2:49 PM