smoothScrollToPosition淡入淡出动画android

时间:2019-11-29 10:29:50

标签: android android-recyclerview fade

我已经实现了自定义LinearLayoutManager,以覆盖smoothScrollToPosition()并更改速度。

在这里我要应用淡入淡出动画。我该如何申请?

class SpeedyLinearLayoutManager : LinearLayoutManager {

constructor(context: Context) : super(context) {}

constructor(context: Context, orientation: Int, reverseLayout: Boolean) : super(
    context,
    orientation,
    reverseLayout
) {
}

constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(
    context,
    attrs,
    defStyleAttr,
    defStyleRes
) {
}

override fun smoothScrollToPosition(
    recyclerView: RecyclerView,
    state: RecyclerView.State?,
    position: Int
) {

    val linearSmoothScroller = object : LinearSmoothScroller(recyclerView.context) {

        override fun computeScrollVectorForPosition(targetPosition: Int): PointF? {
            return super.computeScrollVectorForPosition(targetPosition)
        }

        override fun calculateSpeedPerPixel(displayMetrics: DisplayMetrics): Float {
            return MILLISECONDS_PER_INCH / displayMetrics.densityDpi
        }
    }

    linearSmoothScroller.targetPosition = position
    startSmoothScroll(linearSmoothScroller)
}

companion object {

    private val MILLISECONDS_PER_INCH = 1f //default is 25f (bigger = slower)
}
}

非常感谢

0 个答案:

没有答案