Android Compose, the right page of the HorizontalPager stays on top

249 Views Asked by At

I'm trying to create a new library, but I've hit a roadblock with a particular issue, and I want to solve it. Android Compose, the right page of the HorizontalPager stays on top, but I want it to appear below the current page. How can I do?

Image here

HorizontalPager(
        modifier = modifier,
        state = state,
        pageSize = pageSize,
        beyondBoundsPageCount = beyondBoundsPageCount,
        pageCount = pageCount,
        verticalAlignment = verticalAlignment,
    ) { page ->
        Box(
            modifier = Modifier
                .padding(
                    start = 32.dp,
                    end = 32.dp,
                )
                .graphicsLayer {
                    val startOffset = state.startOffsetForPage(page).absoluteValue
                    translationX = size.width * (startOffset * .97f)
                    translationY = size.width * (startOffset * .1f)
                    alpha = (2f - startOffset) / 2f
                    scaleY = 1f - (startOffset * .3f)
                    scaleX = 1f - (startOffset * .3f)
                }
                .graphicsLayer {
                    val endOffset = state.endOffsetForPage(page).absoluteValue
                    translationX = -size.width * (endOffset * .97f)
                    translationY = -size.width * (endOffset * -.1f)
                    alpha = (2f - endOffset) / 2f
                    scaleY = 1f - (endOffset * .3f)
                    scaleX = 1f - (endOffset * .3f)
                }
                .clip(RoundedCornerShape(20.dp)),
        ) {
            content(page)
        }
    }

I tried to center vertically but it doesn't work in this case

0

There are 0 best solutions below