Skip to content

Instantly share code, notes, and snippets.

@momvart
Last active August 3, 2019 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save momvart/461d39b156e1237a30f5bd042be12b2e to your computer and use it in GitHub Desktop.
Save momvart/461d39b156e1237a30f5bd042be12b2e to your computer and use it in GitHub Desktop.
A simple android LinearSmoothScroller which scrolls to put the target item to the top of the RecyclerView
class StartLinearSmoothScroller(context: Context): LinearSmoothScroller(context) {
override fun getVerticalSnapPreference() = SNAP_TO_START
}
//Example
val smoothScroller = StartLinearSmoothScroller(context)
smoothScroller.targetPosition = 0 //replace with your target position
layoutManager.startSmoothScroll(smoothScroller)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment