如何为recylerview实现轮播效果

时间:2019-04-18 09:54:03

标签: android android-recyclerview carousel linearlayoutmanager

我正在尝试在recyclerView like this中实现类似轮播的效果。我找不到合适的功能来缩放和移动视图。另外,到达recyclerview顶部的视图不得滚动到recyclerview的边缘,而要坚持住

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)
    }

我已经尝试了一些解决方案,例如carousellayoutmanager,但是它们全部缩放了所有视图,而不是在recyclerview的中心

0 个答案:

没有答案