其中中心项目规模比其他项目大。我已经找到了一种方式来扩展所有的项目,或所谓的旋转木马效果。但是,这不是我想要的。我想只有比例的中心项目,并保持其他项目的默认大小。
这是我在其他的答案中发现:
override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
val snapHelper = LinearSnapHelper()
snapHelper.attachToRecyclerView(recyclerView)
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
val layoutManager = recyclerView.layoutManager!!
val midpoint = layoutManager.width / 2f
val distance = shrinkDistance * midpoint
for (i in 0 until layoutManager.childCount) {
val child = layoutManager.getChildAt(i)!!
val childMidpoint = (layoutManager.getDecoratedRight(child) + layoutManager.getDecoratedLeft(child)) / 2f
val d = Math.min(distance, Math.abs(midpoint - childMidpoint))
val scale = 1 + -shrinkAmount * d / distance
child.scaleX = scale
child.scaleY = scale
}
}
})
}
正如我所说的,这个尺度所有可见的物品,在这里我只想放大中心项目。
你可以给孩子中间不同的缩放。
计算与childCount老二,并使用不同的缩放它比其他。