Azoft / CarouselLayoutManager

Android Carousel LayoutManager for RecyclerView
Apache License 2.0
2.56k stars 367 forks source link

How to increase the space between items ? #101

Closed Morteza-Rastgoo closed 3 years ago

root-ansh commented 5 years ago

i also have a similar doubt, i want to decrease space. Its showing a lot of space between the central and its adjacent views

MohamedElshafey commented 4 years ago

faced the same issue and i bring up with this solution:

`class CustomCarouselZoomPostLayoutListener : CarouselLayoutManager.PostLayoutListener {
    override fun transformChild(child: View, itemPositionToCenterDiff: Float, orientation: Int): ItemTransformation {
        val scale = (2 * (2 * -StrictMath.atan(Math.abs(itemPositionToCenterDiff) + 1.0) / Math.PI + 1)).toFloat()
        // because scaling will make view smaller in its center, then we should move this item to the top or bottom to make it visible
        val translateY: Float
        val translateX: Float
        val ratio = 1.4f // Change this ratio to get your customized spacing
        if (CarouselLayoutManager.VERTICAL == orientation) {
            val translateYGeneral = child.measuredHeight * (1 - scale) * ratio
            translateY = Math.signum(itemPositionToCenterDiff) * translateYGeneral
            translateX = 0f
        } else {
            val translateXGeneral = child.measuredWidth * (1 - scale) * ratio
            translateX = Math.signum(itemPositionToCenterDiff) * translateXGeneral
            translateY = 0f
        }

        return ItemTransformation(scale, scale, translateX, translateY)
    }
}`