1

I'm trying to implement the carousel-like effect in recyclerView like this. I can't find the right function for scaling and moving the views. Also, the views that reached the top of recyclerview must not scroll out of recyclerview's edges but stick to them

override fun scrollVerticallyBy(dy: Int, recycler: RecyclerView.Recycler?, state: RecyclerView.State?): Int {
        for (i in 0 until childCount) {
            val item = getChildAt(i)
            val recyclerCenter = height / 2f
            val distance = max(abs(recyclerCenter - getDecoratedTop(item!!) / 2f), recyclerCenter - getDecoratedTop(item) / 2f)
            val ratio = (recyclerCenter - item.height / 2f - distance) / (recyclerCenter - item.height / 2f) + 1
            item.translationZ = (ratio * 1000f)
            item.alpha = ratio
            item.translationY = -(ratio.pow(2)*10)
            item.scaleX = ratio
            item.scaleY = ratio
        }
        return super.scrollVerticallyBy(dy, recycler, state)
    }

I've already tried some solutions, like carousellayoutmanager, but all of them scaling all views, that not in center of recyclerview

Tanveer Munir
  • 1,956
  • 1
  • 12
  • 27
Dmitry
  • 11
  • 4
  • I don't think there's an easy way to do it outside of inheriting a RecyclerView. Layouting is done in onLayoutChildren I believe. BUT you can use CarouselLayoutManager but instead of using standard PostLayoutListener you can write your own. All transformation is calculated here: https://github.com/Azoft/CarouselLayoutManager/blob/master/CarouselLayoutManager/carousel/src/main/java/com/azoft/carousellayoutmanager/CarouselZoomPostLayoutListener.java Just make your own and attach it to CarouselLayoutManager by setPostLayoutListener. – IcedLance Apr 18 '19 at 10:33
  • Did you mean this https://developer.android.com/reference/android/widget/StackView – hemen Apr 18 '19 at 14:16

0 Answers0