Created
February 28, 2015 08:36
-
-
Save mzgreen/09ef2f24440fbef5f17a to your computer and use it in GitHub Desktop.
HidingScrollListener class with fixed top position hiding
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 float HIDE_THRESHOLD = 10; | |
private static final float SHOW_THRESHOLD = 70; | |
private int mToolbarOffset = 0; | |
private boolean mControlsVisible = true; | |
private int mToolbarHeight; | |
private int mTotalScrolledDistance; | |
public HidingScrollListener(Context context) { | |
mToolbarHeight = Utils.getToolbarHeight(context); | |
} | |
@Override | |
public void onScrollStateChanged(RecyclerView recyclerView, int newState) { | |
super.onScrollStateChanged(recyclerView, newState); | |
if(newState == RecyclerView.SCROLL_STATE_IDLE) { | |
if(mTotalScrolledDistance < mToolbarHeight) { | |
setVisible(); | |
} else { | |
if (mControlsVisible) { | |
if (mToolbarOffset > HIDE_THRESHOLD) { | |
setInvisible(); | |
} else { | |
setVisible(); | |
} | |
} else { | |
if ((mToolbarHeight - mToolbarOffset) > SHOW_THRESHOLD) { | |
setVisible(); | |
} else { | |
setInvisible(); | |
} | |
} | |
} | |
} | |
} | |
@Override | |
public void onScrolled(RecyclerView recyclerView, int dx, int dy) { | |
super.onScrolled(recyclerView, dx, dy); | |
//... | |
mTotalScrolledDistance += dy; | |
} | |
//... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment