SHARE
TWEET

Scroll example

vmeansdev Jun 2nd, 2020 (edited) 662 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private fun onSubSharesScrolled() {
  2.     val subSharesLm = subSharesRecyclerView.layoutManager as LinearLayoutManager
  3.     val variantsLm = variantsRecyclerView.layoutManager as LinearLayoutManager
  4.     val first = subSharesLm.findFirstVisibleItemPosition()
  5.     val last = subSharesLm.findLastVisibleItemPosition()
  6.     if (first < 0 || last < 0) {
  7.         // When the list is empty, we get -1 for the positions.
  8.         return
  9.     }
  10.  
  11.     val firstId = verticalVariantIndexes[first]
  12.     val lastId = verticalVariantIndexes[last]
  13.     val range = verticalVariantIndexes.values.indexOf(firstId)..verticalVariantIndexes.values.indexOf(lastId)
  14.     if (range != cachedRange) {
  15.         cachedRange = highlightRange
  16.         val selectedPosition = horizontalVariantIndexes[firstId]
  17.         smoothScroller.targetPosition = selectedPosition ?: return
  18.         variantsLm.startSmoothScroll(smoothScroller)
  19.     }
  20. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top