Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. import android.content.Context
  2. import android.graphics.PointF
  3. import android.support.v7.widget.LinearLayoutManager
  4. import android.support.v7.widget.LinearSmoothScroller
  5. import android.support.v7.widget.RecyclerView
  6.  
  7.  
  8. class SmoothScrollableLinearLayoutManager @JvmOverloads constructor(context: Context, orientation: Int = LinearLayoutManager.VERTICAL, reverseLayout: Boolean = false) : LinearLayoutManager(context, orientation, reverseLayout) {
  9.  
  10. override fun smoothScrollToPosition(recyclerView: RecyclerView, state: RecyclerView.State, position: Int) {
  11. startSmoothScroll(TopSnappedSmoothScroller(recyclerView.context).apply {
  12. targetPosition = position
  13. })
  14. }
  15.  
  16. private inner class TopSnappedSmoothScroller(context: Context) : LinearSmoothScroller(context) {
  17.  
  18. override fun computeScrollVectorForPosition(targetPosition: Int): PointF {
  19. return this@SmoothScrollableLinearLayoutManager.computeScrollVectorForPosition(targetPosition)
  20. }
  21.  
  22. override fun getVerticalSnapPreference(): Int = SNAP_TO_START
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement