import androidx.recyclerview.widget.LinearSmoothScroller
import androidx.recyclerview.widget.RecyclerView
/**
- 滑动到指定位置,并使指定位置位于列表最上面
*/
fun RecyclerView.scrollItemToTop(position: Int) {
val smoothScroller: LinearSmoothScroller = object : LinearSmoothScroller(context) {
override fun getVerticalSnapPreference(): Int {
return SNAP_TO_START
}
}
smoothScroller.targetPosition = position
layoutManager?.startSmoothScroll(smoothScroller)
}