RecyclerView -如何设置自定义滚动插值器



我以编程方式创建RecyclerView:


private fun initRecyclerView() {
RecycleView(context).apply {
setHasFixedSize(true)
layoutManager = LinearLayoutManager(context, VERTICAL, true)
adapter = SlotAdapter().apply { submitList(cells) }
}
addView(slot)
}

RecycleView。smoothScrollBy(dx: Int, dy: Int, interpolator: interpolator, duration: Int)

fun startSpinning() {
val bottom = slot.bottom
val interpolator = PathInterpolatorCompat.create(0.40f, 0.55f, 0.15f, 0.75f)
slot.smoothScrollBy(0, -bottom.dp, interpolator, 5000)
}

Dp

val Int.dp: Int
get() = (this * Resources.getSystem().displayMetrics.density + 0.5f).toInt()

插入器

创建自定义插值器使用{PathInterpolatorCompat。贝塞尔曲线- http://www.css3beziercurve.net/

最新更新