diff options
Diffstat (limited to 'src/com/android/launcher3/BaseRecyclerView.java')
-rw-r--r-- | src/com/android/launcher3/BaseRecyclerView.java | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/com/android/launcher3/BaseRecyclerView.java b/src/com/android/launcher3/BaseRecyclerView.java index 77925b5b3..cdf9aa2aa 100644 --- a/src/com/android/launcher3/BaseRecyclerView.java +++ b/src/com/android/launcher3/BaseRecyclerView.java @@ -77,7 +77,7 @@ public abstract class BaseRecyclerView extends RecyclerView mDeltaThreshold = getResources().getDisplayMetrics().density * SCROLL_DELTA_THRESHOLD_DP; ScrollListener listener = new ScrollListener(); - setOnScrollListener(listener); + addOnScrollListener(listener); } private class ScrollListener extends OnScrollListener { @@ -286,8 +286,7 @@ public abstract class BaseRecyclerView extends RecyclerView // Calculate the current scroll position, the scrollY of the recycler view accounts for the // view padding, while the scrollBarY is drawn right up to the background padding (ignoring // padding) - int scrollY = getPaddingTop() + - (scrollPosState.rowIndex * scrollPosState.rowHeight) - scrollPosState.rowTopOffset; + int scrollY = getCurrentScroll(scrollPosState); int scrollBarY = mBackgroundPadding.top + (int) (((float) scrollY / availableScrollHeight) * availableScrollBarHeight); @@ -302,6 +301,15 @@ public abstract class BaseRecyclerView extends RecyclerView } /** + * @param scrollPosState current state of view scrolling. + * @return the vertical scroll position + */ + protected int getCurrentScroll(ScrollPositionState scrollPosState) { + return getPaddingTop() + (scrollPosState.rowIndex * scrollPosState.rowHeight) - + scrollPosState.rowTopOffset; + } + + /** * Maps the touch (from 0..1) to the adapter position that should be visible. * <p>Override in each subclass of this base class. */ |