Created
February 15, 2015 11:18
-
-
Save mzgreen/c48f1ae85d66a046d012 to your computer and use it in GitHub Desktop.
HideOnScrollExample - HidingScrollListener class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class HidingScrollListener extends RecyclerView.OnScrollListener { | |
private static final int HIDE_THRESHOLD = 20; | |
private int scrolledDistance = 0; | |
private boolean controlsVisible = true; | |
@Override | |
public void onScrolled(RecyclerView recyclerView, int dx, int dy) { | |
super.onScrolled(recyclerView, dx, dy); | |
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; | |
} | |
} | |
public abstract void onHide(); | |
public abstract void onShow(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment