Skip to content

Instantly share code, notes, and snippets.

@mzgreen
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save mzgreen/b386f4fb5d3cd82b0de0 to your computer and use it in GitHub Desktop.

Select an option

Save mzgreen/b386f4fb5d3cd82b0de0 to your computer and use it in GitHub Desktop.
HideOnScrollExample - HidingScrollListener fixed onScroll
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int firstVisibleItem = ((LinearLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPosition();
//show views if first item is first visible position and views are hidden
if (firstVisibleItem == 0) {
if(!controlsVisible) {
onShow();
controlsVisible = true;
}
} else {
if (scrolledDistance > HIDE_THRESHOLD && controlsVisible) {
onHide();
controlsVisible = false;
scrolledDistance = 0;
} else if (scrolledDistance < -HIDE_THRESHOLD && !controlsVisible) {
onShow();
controlsVisible = true;
scrolledDistance = 0;
}
}
if((controlsVisible && dy>0) || (!controlsVisible && dy<0)) {
scrolledDistance += dy;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment