Skip to content

Instantly share code, notes, and snippets.

@saturov
Created August 16, 2018 12:10
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 saturov/88e467ac8ff9116cb4dbcb681f50c078 to your computer and use it in GitHub Desktop.
Save saturov/88e467ac8ff9116cb4dbcb681f50c078 to your computer and use it in GitHub Desktop.
post_content_rv.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView?, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
val rateViewInRecyclerView: View? =
postAdapter.stickyLayoutManager.findViewByPosition(postItems.indexOf(rateBaseItem))
if (rateViewInRecyclerView != null) {
if (rateViewInRecyclerView.yLocationInWindow() != 0 &&
(rateViewInRecyclerView.yLocationInWindow() < initialRateViewYPosition)) {
post_rate_container?.animate()?.yBy((
rateViewInRecyclerView.yLocationInWindow() -
post_rate_container.yLocationInWindow()).toFloat())?.setDuration(0)?.start()
}
}
}
override fun onScrollStateChanged(recyclerView: RecyclerView?, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
if (newState == SCROLL_STATE_IDLE) {
val rateViewInRecyclerView: View? =
postAdapter.stickyLayoutManager.findViewByPosition(postItems.indexOf(rateBaseItem))
if (rateViewInRecyclerView == null || rateViewInRecyclerView.yLocationInWindow() > initialRateViewYPosition) {
if (post_rate_container != null) {
post_rate_container.animate()?.yBy((
initialRateViewYPosition -
post_rate_container.yLocationInWindow()).toFloat())?.setDuration(100)?.start()
}
}
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment